【问题标题】:Android Intent to Google Maps Navigation using Google Place id (not by Coordinates or Address)Android Intent to Google Maps Navigation using Google Place id (not by Coordinates or Address)
【发布时间】:2020-08-12 12:00:03
【问题描述】:

来自谷歌, 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);

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

【问题讨论】:

  • 我认为documentation 对此非常清楚:q:设置导航搜索的终点。该值可以是纬度、经度坐标或查询格式的地址。也就是说,我不明白为什么到地点 id 的路线会有所不同或不太准确,或者如果您使用地点坐标的话。跨度>
  • 我也相信它不应该有所不同。但事实是,经过大量测试后,它会到达不正确的建筑物/位置。错误率相当高。所以我提出了这个问题。
  • 那你为什么不分享一个例子呢?
  • 如果您需要在当前位置和目的地之间绘制路径或方向,请参阅带有 placeId 的 uri API(我不使用逐向导航):Intent intent = new Intent(Intent. ACTION_VIEW); intent.setData(Uri.parse("google.com/maps/dir/…)); startActivity(intent);
  • 我的客户想直接打开导航

标签: android google-maps android-intent navigation


【解决方案1】:

取自docs

如您在第一行中所见,api 端点有两个参数 - queryquery_place_idquery 如果您有地点 id,则不需要准确,因为地点 id 要准确得多,所以您可以看到我只是输入了一个填充字符串(api 中仍然需要该参数)。在端点中添加您的地点 ID 并设置如图所示的意图,这是在 Android 手机上打开 Google 地图导航的正确意图。

Uri gmmIntentUri = Uri.parse("https://www.google.com/maps/search/?api=1&query=qwerty&query_place_id=" + loc_id);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);

【讨论】:

    【解决方案2】:

    似乎不可能直接使用placeId int 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)
    }
    

    【讨论】:

    • 导航正确率只有70%,所以需要使用placeId
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-10
    • 2019-03-15
    • 1970-01-01
    • 2017-03-20
    • 1970-01-01
    • 2011-02-09
    相关资源
    最近更新 更多