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

后端 未结 1 689
灰色年华
灰色年华 2020-12-11 23:22

First i create a Map with user location

-(void)initGogleMapView{

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:currentLocation.coordinat         


        
相关标签:
1条回答
  • 2020-12-12 00:19

    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;
    }
    
    0 讨论(0)
提交回复
热议问题