2

我正在从我的应用程序启动 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?
                        }

                    }
                });

请帮我解决一下这个。

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

4

0 回答 0