Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
601 views
in Technique[技术] by (71.8m points)

objective c - Google Maps iOS SDK: How do I get accurate latitude and longitude coordinates from a camera's visibleRegion?

EDIT: This is now a confirmed bug with this SDK

I'm using version 1.1.1.2311 of the Google Maps for iOS SDK, and I'm looking to find the bounding latitude and longitude coordinates for the visible map on screen.

I'm using the following code to tell me what the current projection is:

NSLog(@"
%@,%@
%@,%@
%@,%@
%@,%@
",
    [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]);

From reading the headers, it seems that it may not be updated when the camera moves. Fair enough...

/**
 * 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).
 */

But, it appears to update each time the delegate method is called, so I attempted to plot the coordinates to test them...

For the following on my phone:

my app's current projection

The output of the NSLog from above gives me the following:

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

When plotting those coordinates using this I get a projection that seems off:

actual projection

These coordinates are consistent across app launches which leads me to believe that I'm either consistently doing something wrong, I'm misunderstanding what visibleRegion is, or I've discovered a bug. Anyone care to help me figure out which one it is?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To get the bounding latitude and longitude you have to do the following steps:

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;

Best regards Robert


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...