2017-03-19 10 views
0

私は、ユーザーがボタンでズームアウトやズームのいずれかをクリックした場合に実行される次のコードを持っている:ユーザーが離れて上記のデフォルトの座標から移行し、いずれかのボタンをクリックした場合、彼/彼女は、しかし現在のmapViewに基づいて緯度と経度の座標を動的に格納する方法は?

- (void)zoomHandler:(CGFloat)currentZoom 
{ 
GMSCameraPosition *camera = [GMSCameraPosition **cameraWithLatitude:40.790218 longitude:-73.959722** zoom:currentZoom]; 
self.mapView.camera = camera; 
} 

を上記のデフォルト座標に戻ります。ユーザーは、表示されている現在のmapViewをズームイン/ズームアウトできるようにしてください。上の方法で宣言された座標に自動的に戻されません。

どのように達成できますか?

答えて

0

あなたの現在の座標位置を保存するために、2つの変数を作成します。

CLLocationDegrees latitude,longitude; 

     -(void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position 
     { 
     CGPoint point = self.mapView.center; 
     CLLocationCoordinate2D coor = [mapView.projection coordinateForPoint:point]; 
     longitude = coor.longitude; 
     latitude = coor.latitude; 
     } 

あなたはズームを実行するには、以下の方法でコードを使用することがあります。

 -(void)zoomInAction { 
     CGFloat currentZoom = self.mapView.camera.zoom; 
     currentZoom = currentZoom + 1.0; 

     if(currentZoom < self.mapView.maxZoom) { 
      GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude 
                    longitude:longitude 
                     zoom:currentZoom]; 
      self.mapView.camera = camera; 
      [self.mapView animateToCameraPosition:camera]; 
      } 
     } 

     -(void)zoomOutAction { 
     CGFloat currentZoom = self.mapView.camera.zoom; 
     currentZoom = currentZoom - 1.0; 
     if(currentZoom > self.mapView.minZoom) { 
     GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude 
                   longitude:longitude 
                     zoom:currentZoom]; 
      self.mapView.camera = camera; 
      [self.mapView animateToCameraPosition:camera]; 
      } 
     } 
関連する問題