How do I prevent 'GMSMapView' from Infinite horizontal scrolling?

后端 未结 2 1025
南旧
南旧 2020-12-21 13:18

How do I prevent \'GMSMapView\' on IOS 7 from Infinite horizontal scrolling? I am using a \'MKTileOverlay\' and \'kGMSTypeNone\' to show a custom image which stretches all o

2条回答
  •  一整个雨季
    2020-12-21 14:15

    Your code didn't work always, so I improved it (also swift version)

         func mapView(mapView: GMSMapView, didChangeCameraPosition position: GMSCameraPosition) {
    
            var latitude  = position.target.latitude;
            var longitude = position.target.longitude;
    
            if (position.target.latitude > bounds.northEast.latitude) {
                latitude = bounds.northEast.latitude;
            }
    
            if (position.target.latitude < bounds.southWest.latitude) {
                latitude = bounds.southWest.latitude;
            }
    
            if (position.target.longitude > bounds.northEast.longitude) {
                longitude = bounds.northEast.longitude;
            }
    
            if (position.target.longitude < bounds.southWest.longitude) {
                longitude = bounds.southWest.longitude;
            }
    
            if (latitude != position.target.latitude || longitude != position.target.longitude) {
    
                var l = CLLocationCoordinate2D();
                l.latitude  = latitude;
                l.longitude = longitude;
    
                mapView.animateToLocation(l);
    
            }
        } 
    

提交回复
热议问题