【问题标题】:Google map with multiple annotations带有多个注释的谷歌地图
【发布时间】:2017-07-18 15:22:16
【问题描述】:

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

for (int i = 0; i < [ARR count]; i++)
{
  float latitude_val = [[NSString stringWithFormat:@"%@",[[ARR objectAtIndex:i] valueForKey:@"lat"]] floatValue];
  float longitude_val = [[NSString stringWithFormat:@"%@",[[ARR:i] valueForKey:@"lng"]] floatValue];            
  GMSMarker *marker = [[GMSMarker alloc] init];
  marker.position = CLLocationCoordinate2DMake(latitude_val, longitude_val);           
  marker.map = _mapView;      
}

谢谢

【问题讨论】:

  • 以下几行是否是强制性的 [mkr setTitle:]; [mkr setSnippet:<snippet>]; .如果是这样,我的噘嘴会显示一个注释</snippet>
  • @Lalitkumar 我尝试将 float 更改为 double 但仍显示单个注释
  • @Jayasabeen 你能打印ARR lat & lng 值的值,并在你的问题中添加这些 lat,lng 值吗?

标签: ios objective-c google-maps


【解决方案1】:

检查这个.. 它对我来说工作正常。希望对你也有帮助。

 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"];

}];

【讨论】:

    【解决方案2】:

    设置GMSMapViewGMSCameraPosition

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

    【讨论】:

      猜你喜欢
      • 2012-12-01
      • 2015-07-05
      • 2016-08-28
      • 1970-01-01
      • 1970-01-01
      • 2011-06-12
      • 2018-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多