作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
编辑:现在这是一个已确认的错误 this开发工具包
我正在使用 1.1.1.2311 版的 iOS SDK 谷歌地图,我正在寻找屏幕上可见 map 的边界纬度和经度坐标。
我正在使用以下代码来告诉我当前的投影是什么:
NSLog(@"\n%@,%@\n%@,%@\n%@,%@\n%@,%@\n",
[NSNumber numberWithDouble:mapView.projection.visibleRegion.farLeft.latitude],
[NSNumber numberWithDouble:mapView.projection.visibleRegion.farLeft.longitude],
[NSNumber numberWithDouble:mapView.projection.visibleRegion.farRight.latitude],
[NSNumber numberWithDouble:mapView.projection.visibleRegion.farRight.longitude],
[NSNumber numberWithDouble:mapView.projection.visibleRegion.nearLeft.latitude],
[NSNumber numberWithDouble:mapView.projection.visibleRegion.nearLeft.longitude],
[NSNumber numberWithDouble:mapView.projection.visibleRegion.nearRight.latitude],
[NSNumber numberWithDouble:mapView.projection.visibleRegion.nearRight.longitude]);
从阅读标题来看,似乎它可能不会随着相机移动而更新。很公平......
/**
* The GMSProjection currently used by this GMSMapView. This is a snapshot of
* the current projection, and will not automatically update when the camera
* moves. The projection may be nil while the render is not running (if the map
* is not yet part of your UI, or is part of a hidden UIViewController, or you
* have called stopRendering).
*/
但是,每次调用委托(delegate)方法时它似乎都会更新,所以我试图绘制坐标来测试它们...
对于我手机上的以下内容:
上面 NSLog 的输出为我提供了以下内容:
37.34209003645947,-122.0382353290915
37.34209003645947,-122.010769508779
37.30332095984257,-122.0382353290915
37.30332095984257,-122.010769508779
当使用 this 绘制这些坐标时我得到一个似乎不正确的投影:
这些坐标在应用程序启动时是一致的,这让我相信我一直在做错事,我误解了 visibleRegion 是什么,或者我发现了一个错误。有人愿意帮我弄清楚它是哪一个吗?
最佳答案
要获取边界纬度和经度,您必须执行以下步骤:
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithRegion:self.googleMapsView.projection.visibleRegion];
CLLocationCoordinate2D northEast = bounds.northEast;
CLLocationCoordinate2D northWest = CLLocationCoordinate2DMake(bounds.northEast.latitude, bounds.southWest.longitude);
CLLocationCoordinate2D southEast = CLLocationCoordinate2DMake(bounds.southWest.latitude, bounds.northEast.longitude);
CLLocationCoordinate2D southWest = bounds.southWest;
最好的问候罗伯特
关于objective-c - 谷歌地图 iOS SDK : How do I get accurate latitude and longitude coordinates from a camera's visibleRegion?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15317359/
我是一名优秀的程序员,十分优秀!