iOS MKMapView 不接受大于 45.x 的纬度值?
iOS MKMapView doesn't accept latitude value bigger than 45.x?
如何重现错误:
let mapView = MKMapView.init(frame: UIScreen.mainScreen().bounds)
mapView.region.center = CLLocationCoordinate2D.init(latitude: 60, longitude: 100)
mapView.region.span = MKCoordinateSpanMake(20, 20)
print(mapView.region.center)
self.view = mapView
然后 print 语句打印如下:
CLLocationCoordinate2D(latitude: 44.880507991448255, longitude: 100.00000000000004)
问题是我实际上在第 2 行将纬度设置为 60。但是结果纬度是 44.88x。而且我试过45以上的其他值,它们也不正确。有任何想法吗?谢谢!
这似乎是 Swift 的问题。如果您在 Objective-C
中尝试此代码
mapView.region.center = CLLocationCoordinate2D.init(latitude: 60, longitude: 100)
编译器报错expression is not assignable
。正确的做法是新建一个region,然后将这个region赋给map view:
let region = MKCoordinateRegionMake(CLLocationCoordinate2DMake(60.0,100.0), MKCoordinateSpanMake(20, 20))
mapView.region = region
如何重现错误:
let mapView = MKMapView.init(frame: UIScreen.mainScreen().bounds)
mapView.region.center = CLLocationCoordinate2D.init(latitude: 60, longitude: 100)
mapView.region.span = MKCoordinateSpanMake(20, 20)
print(mapView.region.center)
self.view = mapView
然后 print 语句打印如下:
CLLocationCoordinate2D(latitude: 44.880507991448255, longitude: 100.00000000000004)
问题是我实际上在第 2 行将纬度设置为 60。但是结果纬度是 44.88x。而且我试过45以上的其他值,它们也不正确。有任何想法吗?谢谢!
这似乎是 Swift 的问题。如果您在 Objective-C
中尝试此代码mapView.region.center = CLLocationCoordinate2D.init(latitude: 60, longitude: 100)
编译器报错expression is not assignable
。正确的做法是新建一个region,然后将这个region赋给map view:
let region = MKCoordinateRegionMake(CLLocationCoordinate2DMake(60.0,100.0), MKCoordinateSpanMake(20, 20))
mapView.region = region