谷歌地图绘制多个标记问题(信息窗口和标记重复)

首先我创build一个用户位置的地图

-(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"; } 

然后我有一个经度和纬度的数组和循环的阴谋

  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; } 

标记重复相同的标题。任何人都可以帮助我,我在哪里做错了?

首先检查你的纬度和经度arrays,它可能是重复的。 否则,请执行以下步骤

首先,将GoogleMaps.bundleGoogleMaps.framework添加到您的项目中。 然后当你想实现谷歌地图, #import <GoogleMaps/GoogleMaps.h> ,然后设置委托@interface YourViewController : UIViewController <GMSMapViewDelegate>

.h声明属性

 @property (nonatomic, retain) GMSMapView *gMapView; 

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; 

你在哪里添加了多个标记来映射。

 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; }