2

I'm starting the Google Maps app from my app in order to navigate the user to a certain latitude & longitude.

What I want is, I want to close the Google Maps app as soon as user reach the destination (in other words, when user's current location gets equal to destination location).

This is what i have done so far:

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?
                        }

                    }
                });

Please help me with this.

Please cooperate if the question seems to be badly formatted, I'm still learning to post good questions.

0 Answers0