Android Intent to Google Maps Navigation 使用 Google Place id(不是通过坐标或地址)

red*_*dan 9 navigation android google-maps android-intent

来自谷歌, https://developers.google.com/maps/documentation/urls/android-intents#launch_turn-by-turn_navigation

Uri gmmIntentUri = Uri.parse("google.navigation:q=Taronga+Zoo,+Sydney+Australia");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Run Code Online (Sandbox Code Playgroud)

我可以在导航模式下成功打开谷歌地图,但是,因为在我的应用程序的前一页中,我使用谷歌自动完成功能并获得Place. 还有就是placeId每个地方。问题是如何使用上述逐向导航方法,而placeId不是使用地址或坐标(因为 placeId 比其他方法更准确)。

And*_*nko -2

似乎不可能直接使用placeIdint Turn-by-tyrn 导航意图,但无论如何你可以将坐标传递给Place导航:

Place place = PlaceAutocomplete.getPlace(this, data);

if (place != null) {
    LatLng latLng = place.getLatLng();
    String strLatitude = String.valueOf(latLng.latitude);
    String strLongitude = String.valueOf(latLng.longitude);

    Uri gmmIntentUri = Uri.parse(String.format("google.navigation:q=%s,%s",strLatitude, strLongitude));
    Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
    mapIntent.setPackage("com.google.android.apps.maps");
    startActivity(mapIntent)
}
Run Code Online (Sandbox Code Playgroud)