如何从Android中的应用谷歌地图的回调,当导航完成 [英] How to get a callback from google maps in Android application, when navigation is complete

查看:165
本文介绍了如何从Android中的应用谷歌地图的回调,当导航完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个Android应用程序,这将显示出某些点上的谷歌地图,这是我(LAT,郎)的所有点显示,跟我来。无论何时,用户点击了谷歌地图,这些位置中的一个,我开始一个新的谷歌地图的意图,显示导航给用户,并应该采取用户到(LAT,郎)。

  //假设这个函数被调用的谷歌地图事件的onclick
    起作用的onclick(){
            乌里gmmIntentUri = Uri.parse(google.navigation:Q = 32.885240,-96.763475);
            意图mapIntent =新意图(Intent.ACTION_VIEW,gmmIntentUri);
            mapIntent.setPackage(com.google.android.apps.maps);
            如果(mapIntent.resolveActivity(getPackageManager())!= NULL){
                startActivity(mapIntent);
            }
    }

这将启动用户的导航。
现在我想实现是这样的 -
每当这个导航是完整的,我想某种标志要传递给我的Andr​​oid应用程序,让自己的应用程序知道导航已经完成。

如果有可能的导航已经完成后自动关闭谷歌地图应用程序,这将是不错的。

任何帮助是极大AP preciated。谢谢。任何人有任何方案来解决这个?


解决方案

您需要调用 完成()在到达目的地时,该活动的方法。因此,这里有你需要在你的程序来实现的步骤。


  • 首先知道用户输入的目的地的坐标,它传递方向的API中。

    <$p$p><$c$c>https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&key=API_KEY


  • 当你知道目的地的坐标可以传递时所点击导航意图重新标记presenting。 (你已经做了)


  • 请使用该跟踪当前位置的位置侦听器接口的坐标。


  • 把一个 IF ... ELSE 在您检查当前位置是等同于目标的条件。


  • 在当前位置==目标做出打电话的 activity.finish()将最后关闭托管的地图活动。


希望帮助!

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

//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.

If it is possible to automatically close the google maps application after the navigation has been completed, it will be nice to have.

Any help is greatly appreciated. Thanks. Anyone has any solutions for this?

解决方案

You need to call the finish() method on the activity when the destination is reached. So here are the steps that you need to implement in your program.

  • First of all know the destination coordinates from the user input and pass it in the Direction API.

    https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&key=API_KEY
    

  • When you know the destination coordinates you can pass that when the marker representing that is clicked in the navigation intent. (which you have already done)

  • Make use of the location listener interface that tracks the current location coordinates.

  • Put an if...else condition where you check that the current location is equivalent to the destination.

  • When the current location == Destination make a call to activity.finish() which will finally close the maps activity hosting.

Hope that Helps!!

这篇关于如何从Android中的应用谷歌地图的回调,当导航完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆