gpt4 book ai didi

objective-c - 谷歌地图 iOS SDK : How do I get accurate latitude and longitude coordinates from a camera's visibleRegion?

转载 作者:太空狗 更新时间:2023-10-30 03:31:07 27 4
gpt4 key购买 nike

编辑:现在这是一个已确认的错误 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)方法时它似乎都会更新,所以我试图绘制坐标来测试它们...

对于我手机上的以下内容:

my app's current projection

上面 NSLog 的输出为我提供了以下内容:

37.34209003645947,-122.0382353290915
37.34209003645947,-122.010769508779
37.30332095984257,-122.0382353290915
37.30332095984257,-122.010769508779

当使用 this 绘制这些坐标时我得到一个似乎不正确的投影:

actual projection

这些坐标在应用程序启动时是一致的,这让我相信我一直在做错事,我误解了 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com