1

How I can open Google Maps application on button click event from my current application.

tshepang
  • 10,772
  • 21
  • 84
  • 127
Mehul Santoki
  • 1,198
  • 1
  • 10
  • 25
  • possible duplicate of [Launch Google Maps app](http://stackoverflow.com/questions/2553251/launch-google-maps-app) – CharlesB Jul 23 '12 at 13:26

8 Answers8

5

use below line

String uri = "http://maps.google.com/";
            Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
            intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
            startActivity(intent);

that will redirect in map application.

Sanket Kachhela
  • 10,512
  • 7
  • 46
  • 74
3

You can open google maps with intent giving your starting point and end point.

Intent navigation = new Intent(Intent.ACTION_VIEW, Uri
        .parse("http://maps.google.com/maps?saddr="
                + Constants.latitude + ","
                + Constants.longitude + "&daddr="
                + latitude + "," + longitude));
startActivity(navigation);

This opens any maps application. Means a browser or google maps application. If you just want google maps and get rid of the dialog you can give the intent a hint as to which package you want to use.

Before the startActivity() add this:

intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
san
  • 1,872
  • 13
  • 22
2

You have to use a Intent.

Here you have a real example

http://www.tutorialforandroid.com/2009/10/launching-other-application-using-code.html

Here you have an theoric example

Open another application from your own (intent)

Here you have the Android documentation

http://developer.android.com/reference/android/content/Intent.html

Hope it helps! :)

Community
  • 1
  • 1
axierjhtjz
  • 6,647
  • 6
  • 47
  • 65
1

You can do that by specifying "intent-filters" in your AndroidManifes.xml; for more on how to launch google applications from your application see this link: Intents List: Invoking Google Applications on Android Devices

pixelscreen
  • 1,897
  • 2
  • 16
  • 38
1
WebView view=(WebView) findViewById(R.id.w);    
Button button=(Button) findViewById(R.id.nxt);

button.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                     view.loadUrl("http://maps.google.co.in/maps?hl=en&tab=wl");
                    }
                        };
AkashG
  • 7,627
  • 3
  • 26
  • 43
0

You could use something like this:Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345")); startActivity(intent);

rajeshwaran
  • 1,648
  • 1
  • 18
  • 24
0

This is another way to call google maps from my current app.

String SettingsPage = "com.google.android.apps.maps/com.google.android.maps.MapsActivity";

                try
                {
                Intent intent = new Intent(Intent.ACTION_MAIN);             
                intent.setComponent(ComponentName.unflattenFromString(SettingsPage));             
                intent.addCategory(Intent.CATEGORY_LAUNCHER );             
                startActivity(intent); 
                }
                catch (ActivityNotFoundException e)
                {
                 Log.e("Activity Not Found","");
                }
                catch (Exception e) {
                     Log.e("Activity Not Found",""+e);
                }
Mehul Santoki
  • 1,198
  • 1
  • 10
  • 25
0

use this. hope it works for you:

 Button showMap = (Button) findViewById(R.id.btn_showMap);
 showMap .setOnClickListener(new OnClickListener()
 {
 public void onClick(View v){
 Intent i = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("geo:"+ latitude +","+ longitude ));
 startActivity(i);
 }
 });
Ajay Mistry
  • 819
  • 1
  • 13
  • 25