How to send address in Android Application to Google Maps

tref95 picture tref95 · Jul 18, 2012 · Viewed 8.4k times · Source

Is there a way to set an address in an application so when it is clicked it automatically opens it in Google Maps? I may end up implementing Maps into my application but it is a simple reference app simply to find the address.

Answer

Mark picture Mark · Jul 18, 2012

You do this via an Intent.

The various URI formats you can use are:

geo:latitude,longitude
geo:latitude,longitude?z=zoom
geo:0,0?q=my+street+address
geo:0,0?q=business+near+city

See http://developer.android.com/guide/appendix/g-app-intents.html for more details.

You build the URI, and pass it to the intent, like this.

String uri = "geo:latitude,longitude";
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);

You might also want to make sure that the Google Maps application is actually installed on the device, described here, so you don't run afoul of devices that don't have Google Maps installed (Amazon Kindle, Barnes & Noble Nook, etc.).