【问题标题】:How to know the co-ordinates of selected marker on Google Map如何知道谷歌地图上选定标记的坐标
【发布时间】:2016-08-07 05:43:49
【问题描述】:

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

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

但我的问题是:- 用户可以选择任何标记,而与存储坐标的数组的 indexPath 值无关。那么如何在谷歌地图上为随机选择的标记绘制折线。

【问题讨论】:

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


    【解决方案1】:

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

    marker.position
    

    【讨论】:

    • 帮助不大,它什么也没返回。
    【解决方案2】:

    好吧,我做到了。

    我只需要使用 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-18
      • 2020-03-14
      • 1970-01-01
      • 2019-10-11
      • 2016-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多