简体   繁体   English

Google Maps Navigation-在Android应用程序中使用Google Navigation

[英]Google Maps Navigation - Using Google Navigation in Android Application

I am facing a very strange problem while implementing Google navigation in my Android application. 在我的Android应用程序中实施Google导航时,我面临一个非常奇怪的问题。

I am implementing Google navigation by opening the URL - 我正在通过打开URL实施Google导航-

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

where xxxx means source address and destination address. 其中xxxx表示源地址和目的地址。

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. 但是,当我尝试在设备上运行该应用程序时,该网址会将自身重定向到Google搜索页面。 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. 当我按下后退按钮时,我会得到从当前位置(按照Google地图)到使用反向地理编码获得的当前位置的导航路线。 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. 如果Google导航实施有误,请也帮助我。

Thanks in advance 提前致谢

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);

you can use the code to start the google map app to navigate! 您可以使用代码启动Google Map应用进行导航! ps: dirflg= d; ps:dirflg = d; you can change the parameter "d" means driving car, "w" means walking "r" means by bus or others. 您可以更改参数“ d”表示驾驶汽车,“ w”表示步行“ r”表示乘公共汽车或其他人。

An ideal approach to access maps from android will be to fire an intent from an activity with the required details of source and destination locations instead of trying to call the map url like in desktop. 从android访问地图的理想方法是从活动中激发出具有所需的源位置和目标位置详细信息的意图,而不是像在桌面中那样尝试调用地图URL。 The intent will roughly ike: 目的大致可以理解为:

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

This earlier post has more discussion on this approach. 较早的帖子对此方法进行了更多讨论。 Please check if it suits your requirement 请检查是否符合您的要求

            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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM