ios Google Maps traçant plusieurs problèmes de marqueurs (window d'information et répétition du marqueur)

D'abord, je crée une carte avec l'location de l'user

-(void)initGogleMapView{ GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:currentLocation.coordinate.latitude longitude:currentLocation.coordinate.longitude zoom:1]; mapView = [GMSMapView mapWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64) camera:camera]; [self.view addSubview:mapView]; GMSMarker *marker = [[GMSMarker alloc] init]; marker.position = camera.target; marker.appearAnimation = kGMSMarkerAnimationPop; marker.map = mapView; marker.title=@"Current Location"; } 

Ensuite, j'ai un tableau de la latitude et de la longitude et de l'insortinggue dans la boucle

  for(int i=0;i<[latLongArr count];i++) { GMSMarker *tempmarker = [[GMSMarker alloc] init]; tempmarker.position = CLLocationCoordinate2DMake([[[latLongArr objectAtIndex:i] valueForKey:@"Latitude"] floatValue],[[[latLongArr objectAtIndex:i] valueForKey:@"Longitude"] floatValue]); tempmarker.title=[[latLongArr objectAtIndex:i] valueForKey:@"Name"]; tempmarker.appearAnimation = kGMSMarkerAnimationPop; tempmarker.map = mapView; } 

Les marqueurs se répètent avec le même titre. Est-ce que quelqu'un peut m'aider là où je me trompe?

Tout d'abord, vérifiez votre Latitude et Longitude dans le tableau, il pourrait être des duplicates. Sinon, suivez les étapes:

Tout d'abord, ajoutez GoogleMaps.bundle et GoogleMaps.framework à votre projet. Et puis, lorsque vous souhaitez implémenter google map, #import <GoogleMaps/GoogleMaps.h> , définissez délégué @interface YourViewController : UIViewController <GMSMapViewDelegate> .

Déclarer la propriété dans votre .h

 @property (nonatomic, retain) GMSMapView *gMapView; 

Dans viewDidLoad()

 GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:appDelegate.currentLoc.coordinate.latitude longitude:appDelegate.currentLoc.coordinate.longitude zoom:6]; self.gMapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; self.gMapView.delegate = self; self.gMapView.myLocationEnabled = YES; self.gMapView.mapType = kGMSTypeSatellite; self.view = self.gMapView; GMSMarker *curLocation = [[GMSMarker alloc] init]; curLocation.title = @"Current Location"; curLocation.appearAnimation = kGMSMarkerAnimationPop; curLocation.position = CLLocationCoordinate2DMake(appDelegate.currentLoc.coordinate.latitude, appDelegate.currentLoc.coordinate.longitude); curLocation.map = self.gMapView; 

Où vous avez ajouté plusieurs marqueurs à mapper.

 for(int i=0;i<[latLongArr count];i++) { GMSMarker *marker = [[GMSMarker alloc] init]; marker.position = CLLocationCoordinate2DMake([[(NSDictionary *)[latLongArr objectAtIndex:i] valueForKey:@"Latitude"] doubleValue], [[(NSDictionary *)[latLongArr objectAtIndex:i] valueForKey:@"Longitude"] doubleValue]); marker.appearAnimation = kGMSMarkerAnimationPop; marker.title = @"Title"; marker.snippet = @"Sub title"; marker.map = self.gMapView; }