2017-02-25 42 views
2

我在我的android应用程序中添加了标记,但我需要制作一个功能,如果我在街道上添加标记,我需要在最近的已知街道上添加标记。就像在这个例子中:Add marker to nearest known street,但我需要使用android。Android:从标记点得到最近的街道

,这是我的标记坐标:

MarkerOptions marker = new MarkerOptions().position(
         markerLatLng = new LatLng(point.latitude, point.longitude)).title("my marker"); 

现在我需要执行异步任务发送坐标,谷歌和检索最近的路coordinates.What网址我应该使用吗?

然后我打算坐标添加到ArrayList中:

locationArray.add(new LatLng(point.latitude, point.longitude)); 

,并显示标记在我的地图:

mGoogleMap.addMarker(marker); 

我在API管理器中开启:Google Maps Directions APIGoogle Maps Roads API

问题是什么URL在我的AsynTask应该用来获得最近的街道坐标?

也许我需要使用这个:https://maps.googleapis.com/maps/api/directions/output?parameters并将我的标记坐标添加到参数?

回答

2

你知道如何使用JSON我提出以下建议:

https://maps.googleapis.com/maps/api/geocode/json?latlng=yourLat,yourLng 

在响应中,你将有关于经纬度,最近街道和号码,城市,州,国家,还有更多的所有信息。

+0

所以,要找到最近的街道,我应该使用'DirectionsAPI'还是'GeocodeAPI'? – Darius92

+0

地理编码,如果在方向api中尝试此操作,您将获得“无效请求”。 –

0

如果您的目的是将坐标调整到最近的道路,您应该考虑具有最近道路功能的道路API。

看一看文档

https://developers.google.com/maps/documentation/roads/nearest

这样就可以在异步任务中使用的URL是一样的东西https://roads.googleapis.com/v1/nearestRoads?parameters&key=YOUR_API_KEY

如果你的目的是要找到最近的街道地址的正如Henrique所建议的,反向地理编码对此很有帮助。

+0

使用nearestRoads时,位置不是很准确,有时候标记会错过道路。要获得更多认证,请使用:https://roads.googleapis.com/v1/snapToRoads?path = 54.473155,-6.342999&interpolate = true&key = API_KEY – Lunatikul