【问题标题】:Open Inbuilt Map Intent For Driving Direction打开用于驾驶方向的内置地图意图
【发布时间】:2012-06-20 19:33:52
【问题描述】:

我想打开一个inbuilt google map intent 来显示两个地方之间的路线而不打开一个complete action dialog, which asked for Browser and Map

我试过了。

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+PreferenceData.getLatitude(HotelInfomation.this)+","+PreferenceData.getLongitude(HotelInfomation.this)+"&daddr="+latitude+","+longitude));
startActivity(intent);

但它会打开一个对话框,询问使用浏览器或地图完成操作。我不想要那个 Dialog 。

【问题讨论】:

  • 可能不想要那个对话框。您的一些用户会 - 毕竟,他们可能更喜欢使用不同的地图应用程序。如果他们厌倦了对话框,您的用户完全有能力在选择器中选中“立即将此操作设为默认值”。
  • @CommonsWare,感谢您的宝贵建议。我会按照你的建议去做。

标签: android google-maps


【解决方案1】:
without open a complete action dialog, which asked for Browser and Map

在这种情况下,您需要告诉 android 您要使用哪个应用程序来显示地图。

给你

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?saddr="+PreferenceData.getLatitude(HotelInfomation.this)+","+PreferenceData.getLongitude(HotelInfomation.this)+"&daddr="+latitude+","+longitude));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);

【讨论】:

  • 这不可靠。对于初学者来说,谷歌地图并不适用于所有设备。其次,Google 需要做的就是重构他们的应用程序,或者更改该活动上的exported 标志,然后这段代码就会中断。事实上,由于 Android 设备上安装了许多版本的 Google 地图,因此完全有可能今天这在所有设备上都不起作用。切勿在类名和包名中硬编码不属于您自己的应用程序。
  • @VipulShah:嗯,“解决方法”是简单地允许用户使用选择器。或者,使用geo: URL 而不是http: URL,但如果用户安装了多个地图应用程序(例如,Google Maps 和 OsmAnd),这仍然会显示一个选择器。
【解决方案2】:
    Intent intent = new Intent(
                            android.content.Intent.ACTION_VIEW,
                            Uri.parse("http://maps.google.com/maps?saddr="
                                    + Data.map_latitude + ","
                                    + Data.map_longitude + "+&daddr="
                                    + Data.infoLatitude + ","
                                    + Data.infoLogitute + ""));

【讨论】:

    猜你喜欢
    • 2011-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-30
    • 1970-01-01
    • 1970-01-01
    • 2018-12-12
    相关资源
    最近更新 更多