Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send address in Android Application to Google Maps

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.

like image 964
tref95 Avatar asked Dec 04 '22 03:12

tref95


1 Answers

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.).

like image 199
Mark Avatar answered Dec 24 '22 01:12

Mark