0

Ich habe ein GMSPolygon in GMSMapView hinzugefügt und wenn ich auf die Schaltfläche klicke, um meinen Längen- und Breitengrad für das Polygon zu aktualisieren, wird es überhaupt nicht aktualisiert. Ich kann nur altes Polygon sehen.Google Map GMSPolygon aktualisiert sich nicht in iOS

Dies ist mein Code für die Koordinaten von NSArray und Anzeige eines Polygons, es funktioniert perfekt.

-(void)loadAreasInMap{ 

    for(NSArray *polygon in [[vehicle model] area]){ 
     self.path = [GMSMutablePath path]; 

       for(int i = 0; i < [[polygon valueForKey:@"polygon_coordinates"] count]; i++){ 

        [self.path addCoordinate:CLLocationCoordinate2DMake([[[[polygon valueForKey:@"polygon_coordinates"] objectAtIndex:i] objectAtIndex:1] floatValue],[[[[polygon valueForKey:@"polygon_coordinates"] objectAtIndex:i] objectAtIndex:0] floatValue])]; 
       } 

       GMSPolygon *rectangle = [GMSPolygon polygonWithPath:self.path]; 
       rectangle.fillColor = [UIColor colorWithRed:255.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.4]; 
       rectangle.map = self.mapView; 

    } 

    [self.mapView bringSubviewToFront:self.locationMarkerView]; 
    CLLocation *userLocation = [[locManager sharedManager] userLocation]; 
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:userLocation.coordinate.latitude 
                  longitude:userLocation.coordinate.longitude 
                   zoom:7]; 
    self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 



} 

jetzt, wenn ich auf die Schaltfläche klicken, wird ich diese Methode aufrufen, um meine Koordinaten zu aktualisieren und das Polygon zeichnen wieder, aber ich kann alle Protokolle sehen die Methode sagen ordnungsgemäß funktioniert aber Karte ist die Aktualisierung nicht.

-(void)buttonClicked{ 

    [self.mapView clear]; 
    [self.loadAreasInMap]; 
} 

Bitte mir sagen, wie ich Karte aktualisieren kann

Antwort

0

Was passiert, wenn Sie Ihre Polygon als Instanzvariable definieren, es mit einem Blindpfad laden und die .map-Eigenschaft auf null gesetzt. Wenn Sie dann auf die Schaltfläche klicken, laden Sie das Polygon mit dem neuen Pfad und legen Sie die Karteneigenschaft auf die Kartenansicht fest.

GMSPolygon *rectangle; 

Irgendwo in Ihrer init es mit einem Dummy-Pfad füllen:

GMSMutablePath *path = [[GMSMutablePath alloc] init]; 
    [path addCoordinate:CLLocationCoordinate2DMake(0.0,0.0)]; 
    [path addCoordinate:CLLocationCoordinate2DMake(0.1,0.0)]; 
    [path addCoordinate:CLLocationCoordinate2DMake(0.0,0.1)]; 

    rectangle = [GMSPolygon polygonWithPath:path]; 
    rectangle.map = nil; 

Dann in Ihrer Funktion, laden Sie den neuen Pfad und setzen rectangle.map = mapView;

Sie müssen das ganze nicht löschen Karte dafür.