简体   繁体   English

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

[英]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.bundleGoogleMaps.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.

相关问题 为 iOS 中的谷歌地图分配多个标记,并为每个标记启动 - Assign multiple markers to google maps in iOS with initiating for every marker Google Maps在标记信息窗口iOS中显示语音气泡 - Google Maps Showing speechbubble in marker info window iOS 如何在不点击标记的情况下在 iOS 谷歌地图中显示信息窗口? - How to show a Info window in iOS Google maps without tapping on Marker? Google Maps SDK iOS - 带UIButton的自定义标记信息窗口 - Google Maps SDK iOS - Custom marker info window with UIButton 以编程方式谷歌地图iOS的标记的关闭信息窗口 - Close info window of a marker programmatically google maps iOS 如何使用AFnetworking图像缓存在iOS Google Maps中刷新标记信息窗口? - How to refresh marker info window in iOS Google maps with AFnetworking Image cache? 在Google地图上加载标记的自定义信息窗口时,iOS应用程序冻结 - iOS app freezes when loading custom info window for marker on Google Maps 如何在iOS谷歌地图中显示所有信息窗口而无需点击标记? - How to show all Info window in iOS Google maps without tapping on Marker? 如何在ios上添加一个按钮到谷歌地图标记信息窗口? - How can i add a button to google maps marker info window on ios? 在Google Maps SDK iOS中为所有其他标记设置标记 - Set a marker over all other markers in Google Maps SDK iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM