2013-11-22 52 views
-1

我有一个MKMapKit,并试图根据用户在哪里寻找中心坐标。MKMapView坐标显示0

我用下面的代码获取的坐标了:

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的设备上的所有内容。任何人有任何建议?

谢谢!

+0

此代码是什么?当它“报告0”时,'self.mapView'设置为'nil'?报告如何完成(NSLog,UILabel,其他)?该设备是否与模拟器具有相同的硬件类型和iOS版本? – Anna

+0

@brandontreb你应该使用CLLocationDegrees(又名双)为经纬度等 – Anthony

+0

为什么使用centerCoordinate和地区?试试self.mapView.region.center.latitude和self.mapView.region.center.longitude。正如安娜和阿普拉托所说,绝对检查一个零位mapView并将坐标和长度存储在双精度/ CLLocationDegrees中。 – EricS

回答

0

这显示正确的坐标区域值显示如下

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

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

使用MapView的当前位置值LAN &纬度

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; 
0

它看起来像的MapView出口为零。这是奇怪的,因为它正确地连接起来。一旦我把它设置为一个强有力的参考,一切都很好。也许一些愚蠢的iOS7错误。

感谢所有的反馈家伙!