【发布时间】:2014-10-01 08:32:46
【问题描述】:
我正在开发一个 Android 应用,我需要为用户提供到达某些地方的路线。我有这些地方的坐标,但我发现很难获得用户的当前位置,绕过这个我想知道我是否可以将用户发送到谷歌地图,只显示他想要到达的地方的坐标,谷歌地图会给出给用户的正确方向还是我必须指定他的位置?
【问题讨论】:
标签: android eclipse google-maps coordinates
我正在开发一个 Android 应用,我需要为用户提供到达某些地方的路线。我有这些地方的坐标,但我发现很难获得用户的当前位置,绕过这个我想知道我是否可以将用户发送到谷歌地图,只显示他想要到达的地方的坐标,谷歌地图会给出给用户的正确方向还是我必须指定他的位置?
【问题讨论】:
标签: android eclipse google-maps coordinates
这是我刚刚发现的一个 hack,可以实现你想要的。
String directionsUrl = "https://www.google.co.in/maps/dir/'" + sourceLat + "," + sourceLng + "'/'" + destLat + "," + destLng + "'/";
然后只需使用Intent 打开 URL。
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(directionsUrl));
startActivity(intent);
然后 Android 会提供可以执行该操作的应用程序列表,然后只需选择 Google 地图即可。
【讨论】:
LocationManager 类获取当前位置信息应该不会有太大问题。绘制路线比较棘手。
这会对你有所帮助。
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=srclatitude,srclongitude&daddr=destlat,destlong"));
startActivity(intent);
【讨论】: