2017-03-14 1 views
1

Ich versuche, eine Möglichkeit für den Benutzer einzurichten, den Zoom der Karte zu ändern. Hier ist der Code, den ich habe. Was ist das Problem? Gibt es keine Implementierung zum Aufrufen der Zoom-Funktionalität? oder stelle ich self.mapView.camera zweimal in zwei verschiedenen Funktionen (viewDidLoad und ZoominOutMap) ein?Warum funktioniert diese Zoomfunktion nicht in der Google Maps iOS App?

- (void)viewDidLoad { 
[super viewDidLoad]; 
// Do any additional setup after loading the view. 
//Controls whether the My Location dot and accuracy circle is enabled. 
CGFloat currentZoom = 14.0f; 
self.mapView.myLocationEnabled = YES; 

//adds type of map: kGMSTypeSatellite, kGMSTypeTerrain, kGMSTypeHybrid, kGMSTypeNormal 
self.mapView.mapType = kGMSTypeHybrid; 

//Shows the compass button on the map 
self.mapView.settings.compassButton = YES; 

//Shows the my location button on the map 
self.mapView.settings.myLocationButton = YES; 

//Sets the view controller to be the GMSMapView delegate 
self.mapView.delegate = self; 
GMSCameraPosition *manhattan = [GMSCameraPosition cameraWithLatitude:40.790278 
                 longitude:-73.959722 
                  zoom:14]; 
self.mapView.camera = manhattan; 
} 
//setting up zoom 
-(void)ZoominOutMap:(CGFloat)level 
{ 
self.mapView.delegate = self; 
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:40.790218 longitude:-73.959722 
                  zoom:level]; 
self.mapView.camera = camera; 
} 

-(void)zoomInMapView:(id)sender 
{ 
CGFloat currentZoom; 
currentZoom = currentZoom + 1; 

[self ZoominOutMap:currentZoom]; 
} 

-(void) zoomOutMapView:(id)sender 
{ 
CGFloat currentZoom; 
currentZoom = currentZoom - 1; 

[self ZoominOutMap:currentZoom]; 
} 

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate 
{ 
NSLog(@"You tapped at %f,%f", coordinate.latitude, coordinate.longitude); 
GMSMarker *marker = [[GMSMarker alloc] init]; 
//adds animation for adding marker 
marker.appearAnimation = kGMSMarkerAnimationPop; 
//draw marker on tapped position 
marker.position = CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude); 
marker.map = _mapView; 
//set color of marker and make them draggable 
marker.icon = [GMSMarker markerImageWithColor:[UIColor blueColor]]; 
[marker setDraggable: YES]; 

// Create a rectangular path 
GMSMutablePath *rect = [GMSMutablePath path]; 
[rect addCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude)]; 

// Create the polygon, and assign it to the map. 
GMSPolygon *polygon = [GMSPolygon polygonWithPath:rect]; 
polygon.fillColor = [UIColor colorWithRed:0.25 green:0 blue:0 alpha:0.05]; 
polygon.strokeColor = [UIColor blackColor]; 
polygon.strokeWidth = 2; 
polygon.map = _mapView; 
} 
+0

Ihr Problem gelöst wurde oder nicht? – iOS

+0

nein es war nicht ;; – konyv12

+0

in Ihrem Code, wo Sie Zoomin, Zoomout-Methode aufrufen? – iOS

Antwort

1

Sie vergessen Aktion zu den Schaltflächen hinzufügen: Wenn Tasten sind programmatisch hinzugefügt:

[zoomOut addTarget:self 
      action:@selector(zoomOutMapView:) 
forControlEvents:UIControlEventTouchUpInside]; 
[zoomOut addTarget:self 
      action:@selector(zoomInMapView:) 
forControlEvents:UIControlEventTouchUpInside]; 

Für Storyboard: connecting buttons to action

//zoom controls  
- (IBAction)zoomOut:(id)sender {  

currentZoom = currentZoom - 1;  
[self zoomHandler:currentZoom];  
}  

- (IBAction)zoomIn:(id)sender {  

currentZoom = currentZoom + 1;  
[self zoomHandler:currentZoom];  
}  

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