问题描述
首先我创建一个包含用户位置的地图 - (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 = @当前位置;
}
然后我有一组纬度和经度和情节循环
pre $
for(int i = 0; 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;
}
标记正在重复同样的title.Can任何人都可以帮助我,我在哪里做错了?
首先检查你的经度和纬度的数组,它可能是重复的。否则,请按照以下步骤操作:首先,添加 GoogleMaps.bundle
和 GoogleMaps。 framework
添加到您的项目中。
然后当你想实现谷歌地图时, #import< GoogleMaps / GoogleMaps.h>
,然后设置委托 @interface YourViewController :UIViewController< GMSMapViewDelegate>
。
在 .h
p>
@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 = @当前位置;
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 = @标题;
marker.snippet = @Sub title;
marker.map = self.gMapView;
}
First i create a Map with user location
-(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(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.And then when you want to implement google map, #import <GoogleMaps/GoogleMaps.h>
, then set delegate @interface YourViewController : UIViewController <GMSMapViewDelegate>
.
Declare property in your .h
@property (nonatomic, retain) GMSMapView *gMapView;
In 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;
}
这篇关于ios谷歌地图绘制多个标记问题(信息窗口和标记重复)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!