如何以编程方式关闭谷歌地图应用程序(以意图开始)?

时间:2016-01-22 18:28:54

标签: android google-maps android-intent google-maps-api-3 android-googleapiclient

我正在从我的应用启动Google地图应用,以便将用户导航到某个纬度&经度。

我想要的是,我想在用户到达目的地后立即关闭Google地图应用(换句话说,当用户的当前位置等于目的地位置时)。

这是我到目前为止所做的:

Button btnNavigate = (Button) view.findViewById(R.id.btn_navigate);
                btnNavigate.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                        builder.setMessage(R.string.rtxt);
                        builder.setPositiveButton("Navigate me", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(getActivity(), "Navigating you...", Toast.LENGTH_SHORT).show();
                                Handler handler = new Handler();
                                handler.postDelayed(new Runnable() {
                                    @Override
                                    public void run() {
                                        Uri gmmIntentUri = Uri.parse("google.navigation:q=" + currentLatAcceptS + ", " + currentLngAcceptS);
                                        Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
                                        mapIntent.setPackage("com.google.android.apps.maps");
                                        startActivity(mapIntent);
                                    }
                                }, 1500);
                            }

                        });
                        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(getActivity(), "cancelled", Toast.LENGTH_LONG).show();
                            }
                        });
                        AlertDialog dialog = builder.create();
                        dialog.show();

                        cLatDouble = Double.parseDouble(currentLatAcceptS);
                        cLngDouble = Double.parseDouble(currentLngAcceptS);

                        if (currentLocation.getLatitude() == cLatDouble && currentLocation.getLongitude() == cLngDouble){
                            // what to do here so that google maps get closed as soon as user reach the destination?
                        }

                    }
                });

请帮助我。

如果问题似乎格式错误,请合作,我还在学习发表好问题。

0 个答案:

没有答案