MKMapView坐标显示为0

时间:2013-11-22 00:02:51

标签: ios iphone objective-c ipad mapkit

我有一个MKMapKit,我正在尝试根据用户所在的位置获取中心坐标。

我使用以下代码来获取坐标:

float lat = self.mapView.centerCoordinate.latitude;
float lon = self.mapView.centerCoordinate.longitude;
float latDelta = self.mapView.region.span.latitudeDelta;
float lonDelta = self.mapView.region.span.longitudeDelta;

它在模拟器中工作正常,但报告设备上的所有内容为0。有人有什么建议吗?

谢谢!

2 个答案:

答案 0 :(得分:0)

显示正确,坐标区域值显示如下

CLLocationCoordinate2D topLeftCoord;
    topLeftCoord.latitude = -90;
    topLeftCoord.longitude = 180;

  CLLocationCoordinate2D bottomRightCoord;
    bottomRightCoord.latitude = 90;
    bottomRightCoord.longitude = -180;

使用mapview当前位置值为lan& LAT

float lat = self.mapView.userLocation.location.coordinate.latitude;
float lon = self.mapView.userLocation.location.coordinate.longitude;
float latDelta = self.mapView.region.span.latitudeDelta;
float lonDelta = self.mapView.region.span.longitudeDelta;

答案 1 :(得分:0)

看起来mapView出口是零。这是奇怪的,因为它正确连接。一旦我把它设置为强引用,一切都很好。也许是一些愚蠢的iOS7错误。

感谢所有反馈人员!