简体   繁体   English

Android应用程序可检测Google地图方向何时完成

[英]Android application to detect when Google maps direction is finished

I am building an android application, that will show certain points on google maps, for which I have (lat,lang) for all the points shown, with me. 我正在构建一个Android应用程序,该应用程序将在Google地图上显示某些点,对于我所有显示的点,我都有(lat,lang)。 Whenever, a user clicks on one of these locations on google maps, I am starting a new Google Maps intent which shows navigation to the user and is supposed to take the user to that (lat, lang). 每当用户单击Google地图上的这些位置之一时,我就会启动一个新的Google Maps意图,该意图向用户显示导航,并应将用户带到该位置(经纬度)。

//suppose this function is called on onclick of google maps event
    function onclick(){
            Uri gmmIntentUri = Uri.parse("google.navigation:q=32.885240,-96.763475");
            Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
            mapIntent.setPackage("com.google.android.apps.maps");
            if (mapIntent.resolveActivity(getPackageManager()) != null) {
                startActivity(mapIntent);
            }
    }

This will start the navigation for the user. 这将为用户启动导航。 Now what I want to achieve is this - Whenever this navigation is complete, I want some kind of flag to be passed to my android application, so that my application knows that the navigation has been finished. 现在我想要实现的是-每当导航完成时,我都希望将某种标志传递给我的android应用程序,以便我的应用程序知道导航已完成。

If it is possible to automatically close the google maps application after the navigation has been completed, it will be nice to have. 如果可以在导航完成后自动关闭google maps应用程序,那就太好了。

As @Daniel mentioned, you can use onActivityResult() to detect when users are back. 如@Daniel所述,您可以使用onActivityResult()来检测用户何时返回。 However, if you really want to detect if Google maps direction had finished... You can look at the notifications. 但是,如果您真的想检测Google地图的导航方向是否已完成,则可以查看通知。

So the catch here is, when Google Maps direction is a services, and when it is running, it posts updates to the notifications center. 因此,这里的问题是,当Google Maps Direction是一种服务并且正在运行时,它将更新发布到通知中心。

Which means either you can keep looking at what services are running, or.. get permission to the notifications center and keep checking if Google Maps exists. 这意味着您可以继续查看正在运行的服务,或者..获得通知中心的许可并继续检查Google Maps是否存在。

在此处输入图片说明

I think a better answer since you built the intent for navigation and have the coordinates, is to set up geofencing for the destination or any milestone you want in the trip. 我认为一个更好的答案是,您建立了导航意图并有了坐标,就是为目的地或旅途中想要的任何里程碑设置地理围栏。 After that, you can use your IntentService to retrieve your app at the appropriate activity. 之后,您可以使用IntentService在适当的活动中检索您的应用程序。

https://developer.android.com/training/location/geofencing#java https://developer.android.com/training/location/geofencing#java

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

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