ios google maps plotting multiple markers issues(info window and marker repeating)

╄→尐↘猪︶ㄣ 提交于 2019-12-17 21:09:27

问题


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?


回答1:


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;
}


来源:https://stackoverflow.com/questions/32043284/ios-google-maps-plotting-multiple-markers-issuesinfo-window-and-marker-repeatin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!