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

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


I saw your issue here. Hope that they fix this issue in next update.

But now we can take the real visible region like this:

    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];

Drawing polyline method:

- (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];
}

It works even for map with non-default bearing and angle.


The solution is to download the latest version of the SDK (1.2 at the time of this writing) as the issue has been fixed.

From the 1.2 release notes:

Resolved Issues: - visibleRegion now reports correctly sized region on Retina devices

Download here.