0

I am facing a very strange problem while implementing Google navigation in my Android application.

I am implementing Google navigation by opening the URL -

https://maps.google.co.in/maps?saddr=xxxxxxxxxxxxxxxxxx&daddr=xxxxxxxxxxxxx

where xxxx means source address and destination address.

Using an implicit intent. I am successfully able to get the navigation to the place by opening the web url in desktop.

But when i try to run the application on the device, the url redirects itself to google search page. And when i press back button, i get a navigation route from current location (as per google map), to current location obtained using Reverse Geocoding. In short the url above mentioned does't serve its purpose.

Please help me solve the problem. If the Google navigation implementation is wrong, please help me out in that as well.

Thanks in advance

4

3 回答 3

8
Intent intent = new Intent( Intent.ACTION_VIEW, 
            Uri.parse("http://ditu.google.cn/maps?f=d&source=s_d" +
            "&saddr=31.249351,121.45905&daddr=31.186371,121.489885&hl=zh&t=m&dirflg=d")); 
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK&Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
    startActivity(intent);

您可以使用代码启动谷歌地图应用程序进行导航!ps:dirflg=d;您可以更改参数“d”表示驾驶汽车,“w”表示步行,“r”表示乘公共汽车或其他。

于 2013-07-22T09:31:40.997 回答
3

从 android 访问地图的理想方法是从具有所需源和目标位置详细信息的活动中触发意图,而不是像在桌面中那样尝试调用地图 url。意图大致如下:

Intent navigation = new Intent(Intent.ACTION_VIEW, Uri
        .parse("http://maps.google.com/maps?saddr="
                + Constants.latitude + ","
                + Constants.longitude + "&daddr="
                + latitude + "," + longitude));
startActivity(navigation);

这篇较早的帖子对这种方法进行了更多讨论。请检查是否符合您的要求

于 2013-07-05T14:22:20.573 回答
0
            Intent navigation = new Intent(Intent.ACTION_VIEW, Uri
                    .parse("http://maps.google.com/maps?saddr="
                            + latitude  + ","
                            + longitude +
                            "&daddr="
                            + lat + "," + long1));
           navigation.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK&Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
           navigation.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
            startActivity(navigation);
于 2017-10-11T14:20:24.093 回答