Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Google Map event listener for panning or zooming map?

I want to be able to detect if the user has zoomed out or moved the map center. I have seen post about an event listener but in Javascript and I am trying to see if there is anything in the Google Maps iOS SDK similar to that. I see that iPad Yelp app has something like that, where if you zoom in/out or move the map a Tool Bar appears from the bottom and lets the user know if they want to "Redo Search In Area". I want to do something similar like that and reload the map with other/more markers.

I have looked at Google Map's Reference guide but have not found anything, unfortunately. If anyone has had something similar to this or has any guidance on how this can be accomplished, any information would be great. Thanks in advance!

Link to Google Map Documentation I have looked at:

https://developers.google.com/maps/documentation/ios/reference/protocol_g_m_s_map_view_delegate-p

https://developers.google.com/maps/documentation/ios/reference/interface_g_m_s_coordinate_bounds

like image 411
Chris Avatar asked Feb 07 '14 01:02

Chris


3 Answers

Swift

extension MyMapViewController:GMSMapViewDelegate {

    func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
        //do something
    }
}
like image 75
Peter Kreinz Avatar answered Oct 11 '22 02:10

Peter Kreinz


I use this delegate to detect the camera change, which includes zoom and position:

- (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position;

EDIT

with this code you can get the corners of the visibile area:

NSLog(@"%f,%f",_mapView.projection.visibleRegion.farLeft.latitude,_mapView.projection.visibleRegion.farLeft.longitude);//north west
NSLog(@"%f,%f",_mapView.projection.visibleRegion.farRight.latitude,_mapView.projection.visibleRegion.farRight.longitude);//north east
NSLog(@"%f,%f",_mapView.projection.visibleRegion.nearLeft.latitude,_mapView.projection.visibleRegion.nearLeft.longitude);//south west
NSLog(@"%f,%f",_mapView.projection.visibleRegion.nearRight.latitude,_mapView.projection.visibleRegion.nearRight.longitude);//south east
like image 21
allemattio Avatar answered Oct 11 '22 02:10

allemattio


Try delegate method - (void)mapView:(GMSMapView *)mapView willMove:(BOOL)gesture, the BOOL parameter tells you that the mapView is moved by user or not.

like image 35
Black.Lee Avatar answered Oct 11 '22 02:10

Black.Lee