2013-07-31 41 views
13

tôi sử dụng camera phương pháp với giá trị số như thế này:Cách lấy mức thu phóng hiện tại từ bản đồ google cho ios?

camera = [GMSCameraPosition cameraWithLatitude:37.35 longitude:-122.0 zoom:6]; 

và tôi cần phải tự động vẽ lại bản đồ với vị trí hiện tại thông qua bộ đếm thời gian:

-(void)gmapRedraw{ 
    NSLog(@"gmapRedraw"); 
// self.MapView.camera 
    [locationManager startUpdatingLocation]; 
    NSLog(@"lat %f, lon %f", locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude); 
    camera = [GMSCameraPosition cameraWithLatitude:locationManager.location.coordinate.latitude//37.36//-37.81319//-33.86 
             longitude:locationManager.location.coordinate.longitude//-122.0//144.96298//151.20 
               zoom:6]; 
    self.MapView.camera = camera; 
} 

-(void)timer{ 
    [NSTimer scheduledTimerWithTimeInterval:0.5 
            target:self 
            selector:@selector(gmapRedraw) 
            userInfo:nil 
            repeats:YES]; 
} 

nhưng làm thế nào tôi có thể nhận zoom hiện tại nếu tôi thay đổi nó thông qua chạm?

Trả lời

25

OK, tôi tìm thấy giải pháp, được zoom hiện tại:

CGFloat currentZoom = self.MapView.camera.zoom; 

và sau đó sử dụng nó trong máy ảnh:

camera = [GMSCameraPosition cameraWithLatitude:locationManager.location.coordinate.latitude 
            longitude:locationManager.location.coordinate.longitude 
              zoom:currentZoom]; 
self.MapView.camera = camera; 
1

Bạn có thể sử dụng animateToZoom quá.

self.mapView.animateToZoom(10) 
0

Nếu bạn muốn phát hiện mức Thu phóng trong khi người dùng tương tác với bản đồ. Chúng ta có thể sử dụng Google Map đại biểu Phương pháp

func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) { 
    let zoom = mapView.camera.zoom 
    print("map zoom is ",String(zoom)) 
} 

Dont quên để thêm GMSMapViewDelegate

Các vấn đề liên quan