如何知道所选标记在 Google 地图上的坐标
How to know the co-ordinates of selected marker on Google Map
我想在 google 地图上为 selected 标记绘制折线。我在 Google 地图上固定了大约 20 个标记。这些标记是根据 Google 地点 API 返回的数据绘制的。我将所有坐标存储在一个数组中,然后使用反向地理编码来获取该特定坐标的地址。
然后为了使用标记,我调用了委托方法 didTapMarker 并在其中点击 Google 方向 API。
但我的问题是:- 用户可以 select 任何标记,而不管存储坐标的数组的 indexPath 值如何。那么如何在 Google 地图上为随机 selected 标记绘制折线。
您可以获得被点击的标记。
使用以下 属性 获取其在地图上的位置。
marker.position
嗯,不知何故我做到了。
我只需要使用 GMSMarker 的 userData 属性。
我在“for loop”中为每个标记分配了一个 markerID,如下所示:
marker.userData = @{@"marker_id":[NSString stringWithFormat:@"%d",i]};
然后在 GMSMapView 的 didTapMarker 委托下,我这样调用 Google 方向 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
我想在 google 地图上为 selected 标记绘制折线。我在 Google 地图上固定了大约 20 个标记。这些标记是根据 Google 地点 API 返回的数据绘制的。我将所有坐标存储在一个数组中,然后使用反向地理编码来获取该特定坐标的地址。
然后为了使用标记,我调用了委托方法 didTapMarker 并在其中点击 Google 方向 API。
但我的问题是:- 用户可以 select 任何标记,而不管存储坐标的数组的 indexPath 值如何。那么如何在 Google 地图上为随机 selected 标记绘制折线。
您可以获得被点击的标记。 使用以下 属性 获取其在地图上的位置。
marker.position
嗯,不知何故我做到了。
我只需要使用 GMSMarker 的 userData 属性。 我在“for loop”中为每个标记分配了一个 markerID,如下所示:
marker.userData = @{@"marker_id":[NSString stringWithFormat:@"%d",i]};
然后在 GMSMapView 的 didTapMarker 委托下,我这样调用 Google 方向 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