首页 文章

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

提问于
浏览
0

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

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

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

2 回答

  • 0

    你可以得到被轻拍的标记 . 使用以下属性在 Map 上获取其位置 .

    marker.position
    
  • 0

    不知怎的,我做到了 .

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

    marker.userData = @{@"marker_id":[NSString stringWithFormat:@"%d",i]};
    

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

    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
    

相关问题