【问题标题】:ios google maps plotting multiple markers issues(info window and marker repeating)ios 谷歌地图绘制多个标记问题(信息窗口和标记重复)
【发布时间】:2023-03-09 08:45:01
【问题描述】:

首先我创建一个带有用户位置的地图

-(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循环中绘图

   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;



         }

标记重复使用相同的标题。谁能帮助我在哪里做错了?

【问题讨论】:

  • 能否给出经纬度的数组
  • 我也看到我的地图也在重复,当我滚动地图时,我可以一次又一次地看到相同的国家

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


【解决方案1】:

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

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

在您的 .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;
}

【讨论】:

  • 实际上我看到我的地图也在重复,当我滚动地图时,我可以一次又一次地看到相同的国家
猜你喜欢
  • 2014-07-18
  • 2011-08-21
  • 1970-01-01
  • 2013-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-13
  • 1970-01-01
相关资源
最近更新 更多