Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to (google map iOS) get current map view bound?

how to (google map iOS) get current map view bound? I found ios api is totally different with google map javascript api.

like image 933
hoogw Avatar asked Jul 01 '16 18:07

hoogw


People also ask

What are Google map bounds?

Represents an area in the cartesian plane.


1 Answers

after do some research, below is working code.

// work only on real device, not work on simulator



- (void)mapView:(GMSMapView *)mapView
idleAtCameraPosition:(GMSCameraPosition *)cameraPosition {




    // show current map view bound
    GMSVisibleRegion visibleRegion = [mapView_.projection visibleRegion];
    GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc]initWithRegion: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;


    NSLog(@"NORTH-EST: %.5f",northEast.latitude);
    NSLog(@"NORTH-EST: %.5f",northEast.longitude);

    NSLog(@"NORTH-WEST: %.5f",northWest.latitude);
    NSLog(@"NORTH-WEST: %.5f",northWest.longitude);

    NSLog(@"South-EST: %.5f",southEast.longitude);
    NSLog(@"South-EST: %.5f",southEast.latitude);

    NSLog(@"SOUTH-WEST: %.5f",southWest.latitude);
    NSLog(@"SOUTH-WEST: %.5f",southWest.longitude);


}
like image 163
hoogw Avatar answered Sep 25 '22 07:09

hoogw