2017-08-08 130 views
-2

我有两点的纬度和longutude。我想通过按钮点击从我的应用打开谷歌地图来显示他们之间的路线。如何做?如何显示地图上两点之间的距离

+1

到目前为止你做了什么? –

+0

MapView似乎不提供简单的api方法来做到这一点,但您可以通过map api获取路线点:https://stackoverflow.com/questions/13911279/simplest-way-to-draw-a-route-on-mapview – smora

+0

[如何在Google地图上绘制2点之间的路径]的可能重复(https://stackoverflow.com/questions/21154758/how-to-draw-path-between-2-points-on-google-map) –

回答

0

使用下面的获得在谷歌地图上显示的路线代码...

final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(" 
    http://maps.google.com/maps?" +"saddr=" + sourcelatLng + "&daddr=" + destlatlng; 
    intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); 
    startActivity(intent); 
0

如果你想打开地图应用从源到目的地的路线,你只需要启动以下目的的活动。

Uri routeUri = Uri.parse("http://maps.google.com/maps?saddr=your-lat-1,your-lng-1&daddr=your-lat-2,your-lng-2"); 
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, routeUri); 
startActivity(intent); 

用您的纬度和经度替换您的lat/lng-1/2。

相关问题