如果用户点击缩小或放大按钮,我会执行以下代码:
- (void)zoomHandler:(CGFloat)currentZoom
{
GMSCameraPosition *camera = [GMSCameraPosition **cameraWithLatitude:40.790218 longitude:-73.959722** zoom:currentZoom];
self.mapView.camera = camera;
}
但是,如果用户离开上述默认坐标并单击任一按钮,他/她将被带回上述默认坐标。我希望用户能够在显示的当前mapView上放大/缩小 - 而不是自动恢复到上述方法中声明的坐标。
我如何实现这一目标?
答案 0 :(得分:0)
创建两个变量来存储当前坐标位置:
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];
}
}