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

后端 未结 4 1431
鱼传尺愫
鱼传尺愫 2021-02-19 20:08

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 any

相关标签:
4条回答
  • 2021-02-19 20:49

    Swift

    extension MyMapViewController:GMSMapViewDelegate {
    
        func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
            //do something
        }
    }
    
    0 讨论(0)
  • 2021-02-19 21:04

    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
    
    0 讨论(0)
  • 2021-02-19 21:12

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

    0 讨论(0)
  • 2021-02-19 21:13

    To detect end of moving/zooming Google Map view :

    I came across this question while seeking for how to detect if google map ended up with moving/zooming to get map's centre. I tried capture this event in didChangeCameraPosition as suggested by Allemattio, but that is getting called multiple time as we pan or zoom map. Luckily I found another delegate method of map view that is called when we ended up with panning or zooming map view :

    -(void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position
    {
          NSLog(@"mapView ended with panning/zooming in %s",__PRETTY_FUNCTION__);
    }
    
    0 讨论(0)
提交回复
热议问题