[英]ios google maps plotting multiple markers issues(info window and marker repeating)
First i create a Map with user location 首先,我创建一个包含用户位置的Map
-(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";
}
Then i have an array of latitude and longitude and plot in for loop 然后我有一个纬度和经度数组,并在for循环中绘图
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;
}
Markers are getting repeated with same title.Can anyone help me where i am doing wrong? 标记正在以相同的标题重复出现。任何人都可以在我做错的地方帮助我吗?
First of all check your Latitude and Longitude in array, it might be duplicates. 首先检查数组中的纬度和经度,它可能是重复的。 Otherwise, follow steps :
否则,请按照以下步骤
At very first, add GoogleMaps.bundle
and GoogleMaps.framework
to your project. 首先,将
GoogleMaps.bundle
和GoogleMaps.framework
添加到您的项目中。 And then when you want to implement google map, #import <GoogleMaps/GoogleMaps.h>
, then set delegate @interface YourViewController : UIViewController <GMSMapViewDelegate>
. 然后当你想实现谷歌地图,
#import <GoogleMaps/GoogleMaps.h>
,然后设置委托@interface YourViewController : UIViewController <GMSMapViewDelegate>
。
Declare property in your .h
在
.h
声明属性
@property (nonatomic, retain) GMSMapView *gMapView;
In viewDidLoad()
在
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;
Where you have added multiple markers to map. 您已添加多个标记以进行映射的位置。
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.