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

时间:2015-08-17 05:23:53

标签: ios google-maps google-maps-api-3 google-maps-markers

首先我创建一个包含用户位置的地图

[ODataRoute("Customers({id})")]

然后我有一个纬度和经度数组并在for循环中绘图

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


}

标记正在以相同的标题重复出现。任何人都可以在我错误的地方帮助我吗?

1 个答案:

答案 0 :(得分:0)

首先检查数组中的纬度和经度,它可能是重复的。否则,请按照以下步骤操作:

首先,将GoogleMaps.bundleGoogleMaps.framework添加到您的项目中。 然后,当您想要实施Google地图#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;
}