带有多个注释的Google地图

时间:2017-07-18 06:51:53

标签: ios objective-c google-maps

我是谷歌地图的新手我遵循以下教程https://developers.google.com/maps/documentation/ios-sdk/marker当我尝试使用for循环显示多个注释时,我得到带有单个注释的输出。以下是我的代码,

crisp-edges

由于

2 个答案:

答案 0 :(得分:0)

检查一下..这对我来说很好。我希望它也能帮到你。

 GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:[[[ARR objectAtIndex:0] valueForKey:@"lat"] floatValue]  longitude:[[[ARR objectAtIndex:0] valueForKey:@"lng"] floatValue] zoom:15];

 GMSMapView *googleMapView = [GMSMapView mapWithFrame:CGRectMake(0, 0,self.view.frame.size.width,self.view.frame.size.height) camera:camera];
  googleMapView.myLocationEnabled = YES;
  googleMapView.delegate = self;

[your_Array enumerateObjectsUsingBlock:^(NSDictionary *thumbnailDict, NSUInteger idx, BOOL *stop) {

    // Creates a marker in the center of the map.
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake([[thumbnailDict valueForKey:@"lat"] floatValue],[[thumbnailDict valueForKey:@"lng"] floatValue]);
  //  marker.title = [thumbnailDict valueForKey:@"title"];
  //  marker.snippet = @"Snippet";
    marker.map = googleMapView;
  //  marker.icon = [UIImage imageNamed:@"Map_Annotation"];

}];

答案 1 :(得分:0)

设置GMSCameraPosition-(void)setup { GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:71.00 longitude:45.124 zoom:14 bearing:0 viewingAngle:0]; self.mapView = [GMSMapView mapWithFrame:CGRectMake() camera:camera]; self.mapView.delegate = self; self.mapView.mapType = kGMSTypeNormal; //current location on map self.mapView.myLocationEnabled = YES; //map controls self.mapView.settings.compassButton = YES; self.mapView.settings.myLocationButton = YES; //constraining the zoom options [self.mapView setMinZoom:10 maxZoom:18]; [self.view addSubview:self.mapView]; }

multiple pins

调用此方法在地图上绘制-(void)plotMutliplePinsOnMap:(NSArray *)mapArray { for(int i=0;i<[mapArray count];i++) { double_lat = [[[mapArray objectAtIndex:i]valueForKey:@"latitude"] doubleValue]; double_long = [[[mapArray objectAtIndex:i]valueForKey:@"longitude"] doubleValue]; GMSMarker *mkr = [[GMSMarker alloc] init]; mkr.icon = [UIImage imageNamed:@"map_black"]; if (double_lat !=0 && double_long!=0) { [mkr setPosition:CLLocationCoordinate2DMake(double_lat, double_long)]; [mkr setTitle:[[mapArray objectAtIndex:i] valueForKey:@"placeName"]]; [mkr setSnippet:[[mapArray objectAtIndex:i] valueForKey:@"address"]]; [mkr setMap:self.mapView]; GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:double_lat longitude:double_long zoom:5]; self.mapView.camera=camera; } } }

{{1}}