如何在Google地图上了解所选标记的坐标

时间:2016-04-15 09:56:21

标签: objective-c google-maps-markers google-polyline

我想在谷歌地图上为选定的标记绘制折线。我在谷歌地图上有大约20个标记。标记是根据Google Places API返回的数据绘制的。我将所有坐标存储在一个数组中,然后使用反向地理编码来获取该特定坐标的地址。

然后使用标记,我调用了委托方法didTapMarker,并在里面调用了Google Directions API。

但我的问题是: - 用户可以选择任何标记,而不管存储坐标的数组的indexPath值。那么如何在Google Map上随机选择标记绘制多边形线。

2 个答案:

答案 0 :(得分:0)

您可以获取被点击的标记。 使用以下属性在地图上获取其位置。

marker.position

答案 1 :(得分:0)

不知怎的,我做到了。

我只需要使用GMSMarker的userData属性。 我在“ for loop ”中为每个标记分配了一个markerID,如下所示:

   NSDictionary *tempDic=[[NSDictionary alloc]init];
   tempDic=marker.userData;
   int value= [tempDic[@"marker_id"]intValue];

  NSString *strUrl = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/directions/json?&alternatives=true&origin=%@&destination=%@&key=%@&sensor=false",addressAt,[tempArray objectAtIndex:value],googleAPI_Key];
  //addressAt is the current location of user i.e source and for destination I called the array in which my converted address is stored

然后在GMSMapView的didTapMarker委托下,我这样调用了Google Directions API

mydf