【问题标题】:How to Navigate with Google Maps directly from my application如何直接从我的应用程序使用 Google 地图导航
【发布时间】:2014-06-13 10:19:05
【问题描述】:

早安,

我正在尝试使用 Google 地图将我的应用用户导航到某个地址/位置。根据我目前在网上找到的内容,我尝试了以下方法:

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
                        Uri.parse("http://maps.google.com/maps?saddr=-36.181,27.949&daddr=-36.174732,27.949770"));
                    startActivity(intent);

现在这一切都很好,它打开了谷歌地图,但在我真正进入导航之前它问了我很多事情。

  • 1:它首先让我选择行程
  • 2:然后它会告诉我行程
  • 3:然后我必须单击小箭头(导航按钮)

然后它才开始导航。

我有没有办法在我的意图中指定使用第一条路线并开始立即/自动导航?

第二点,一旦我到达目的地或者我想返回/取消,返回按钮需要带我回到我的应用程序,现在它会返回显示路线,然后我点击再次返回,它说您确定要退出导航。

或者我可以在您到达目的地后收听地图发布的 Intent。那么当用户到达目的地时,我的应用程序将再次成为焦点?

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    试试这个方法

    String urlAddress = "http://maps.google.com/maps?q="+ lat + ","+ lng + "("
                    + your_location_name + ")&iwloc=A&hl=es";
            Intent intent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(urlAddress));
            startActivity(intent);
    

    这将在给定的有效 lat、lng 值上打开谷歌地图,并将 your_location_name 显示为地名。

    【讨论】:

    • 您能否澄清一下,your_location_name 是目标地址吗?以及你当前位置的日志和纬度?
    • 这将在给定的有效 lat、lng 值上打开谷歌地图,并将 your_location_name 显示为地名。
    • 但这不会自动开始导航?
    • @Zapnologica 对不起,我错过了理解。请看看这个stackoverflow.com/questions/2662531/…
    【解决方案2】:
    // try this way,hope this will help you to solve your problem.
    
    String uri = "http://maps.google.com/maps?f=d&hl=es&saddr=-36.181,27.949&daddr=-36.174732,27.949770";
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
    intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
    startActivity(intent);
    

    【讨论】:

    • 产生的结果与我最初的结果相同。
    • 当您尝试通过默认的谷歌地图应用程序显示路线时,我们不会按照他的步骤进行操作,如果您不想要这样的步骤,那么您必须开发您的自定义根实现代码。跨度>
    【解决方案3】:
    String uri = "google.navigation:q=%f, %f";
    Intent navIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String                  .format(Locale.US, uri, customerDropOffLatLng.latitude, customerDropOffLatLng.longitude)));
    navIntent.setPackage("com.google.android.apps.maps");
    startActivity(navIntent);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-31
    • 2018-07-20
    • 2015-12-08
    • 2021-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多