编辑:现在这是一个确认的错误与此 SDK
我使用谷歌地图iOS版SDK的1.1.1.2311版本,我期待找到边界纬度和屏幕上的可视地图经度坐标。
我使用下面的代码来告诉我,目前的预测是什么:
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).
*/
但是,似乎每一个委托方法被调用时进行更新,所以我试图绘制坐标,以测试他们...
对于我的手机上的以下内容:
在NSLog的从上面的输出给了我以下内容:
37.34209003645947,-122.0382353290915
37.34209003645947,-122.010769508779
37.30332095984257,-122.0382353290915
37.30332095984257,-122.010769508779
当使用绘图这些坐标这个我得到的似乎掀起了预测:
这些坐标是整个应用程序启动一致,导致我相信,我要么一直做错了什么,我误解visibleRegion是什么,或者我发现一个bug。 任何人都关心帮助我弄清楚它是哪一个?
为了得到边界的经度和纬度,你必须执行以下步骤:
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;
最好的问候罗伯特
我看到您的问题在这里 。 希望他们修复下次更新这个问题。
但是,现在我们可以采取这样的真正的可视区域:
CGPoint topLeftPoint = CGPointMake(0, 0);
CLLocationCoordinate2D topLeftLocation =
[_mapView.projection coordinateForPoint: topLeftPoint];
CGPoint bottomRightPoint =
CGPointMake(_mapView.frame.size.width, _mapView.frame.size.height);
CLLocationCoordinate2D bottomRightLocation =
[_mapView.projection coordinateForPoint: bottomRightPoint];
CGPoint topRightPoint = CGPointMake(_mapView.frame.size.width, 0);
CLLocationCoordinate2D topRightLocation =
[_mapView.projection coordinateForPoint: topRightPoint];
CGPoint bottomLeftPoint =
CGPointMake(0, _mapView.frame.size.height);
CLLocationCoordinate2D bottomLeftLocation =
[_mapView.projection coordinateForPoint: bottomLeftPoint];
GMSVisibleRegion realVisibleRegion;
realVisibleRegion.farLeft = topLeftLocation;
realVisibleRegion.farRight = topRightLocation;
realVisibleRegion.nearLeft = bottomLeftLocation;
realVisibleRegion.nearRight = bottomRightLocation;
[self drawPolylineWithGMSVisibleRegion:realVisibleRegion color:[UIColor redColor] width:10.0f forMap:mapView];
绘制折线方法:
- (void)drawPolylineWithGMSVisibleRegion:(GMSVisibleRegion)visibleRegion
color:(UIColor*)color
width:(double)width
forMap:(GMSMapView*)mapView{
GMSPolylineOptions *rectangle = [GMSPolylineOptions options];
rectangle.color = color;
rectangle.width = width;
GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:visibleRegion.nearRight];
[path addCoordinate:visibleRegion.nearLeft];
[path addCoordinate:visibleRegion.farLeft];
[path addCoordinate:visibleRegion.farRight];
[path addCoordinate:visibleRegion.nearRight];
rectangle.path = path;
[mapView addPolylineWithOptions:rectangle];
}
它的工作原理,甚至在地图使用非默认轴承和角度。
解决的办法是下载最新版本的SDK(1.2在写这篇文章的时间)的问题已得到修复。
从1.2版本说明:
已解决的问题: - visibleRegion现在报告在视网膜显示设备尺寸正确的区域
下载这里 。
貌似纬度和经度坐标要打印出来,手动绘制的可能断位/被截断。 %F默认只打印出到6位小数。
这里有一个相关的问题可能会有所帮助:
如何打印与iOS上的全精度的双?
也许你给位置管理器错误的准确性..
试着增加它:
locationMgr.desiredAccuracy = kCLLocationAccuracyBest;
电池被耗尽moreyy
文章来源: Google Maps iOS SDK: How do I get accurate latitude and longitude coordinates from a camera's visibleRegion?