首页 > 解决方案 > 如何检测用户何时到达谷歌地图中的目的地?我正在通过我的应用程序中的意图启动 Google 地图

问题描述

这就是我启动谷歌地图的方式。现在我想检测用户何时到达目的地。

    String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?daddr=%f,%f (%s)", drplat, drplong, getAddresss(drplat, drplong));
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
            intent.setPackage("com.google.android.apps.maps");
            try
            {
                context.startActivity(intent);
            }
            catch(ActivityNotFoundException ex)
            {
                try
                {
                    Intent unrestrictedIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                   context.startActivity(unrestrictedIntent);
                }
                catch(ActivityNotFoundException innerEx)
                {
                    Toast.makeText(context, "Please install a maps application", Toast.LENGTH_LONG).show();
                }
            }

标签: androidgoogle-maps

解决方案


您可以使用LocationManager该类,尤其是它的addProximityAlert成员函数。PendingIntent每次手机进入或离开由位置和提供的半径定义的区域时,都会触发您指定的。

添加ProximityAlert


推荐阅读