I have an address param within my app say " 921 Beverly Hills, california, CA- 09001" Upon tapping this I want google maps to open and show annotation for this exact address. How do I do that? Any clue?
How do I open google maps app on tapping an address?
552 views Asked by AudioBubble At
2
There are 2 answers
1
On
There are great resources to get you going this is a sample. In a real app you would want to handle the intent with your own map activity; maybe add bounds and a camera to zoom in or whatever...
Location sf = new Location("");
sf.setLatitude(37.7749);
sf.setLongitude(-122.4194);
requestLocation("your address");
public void requestLocation(Location location) {
// Create a Uri from an intent string. Use the result to
// create an Intent.
Uri gmmIntentUri = Uri.parse("geo:" + location.getLatitude() + "," + location.getLongitude());
// Create an Intent from gmmIntentUri. Set the action to
// ACTION_VIEW
Intent mapIntent = new Intent(Intent.ACTION_VIEW,
gmmIntentUri);
// Make the Intent explicit by setting the Google Maps
// package
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(mapIntent, REQUEST_LOCATION);
}
}
public void requestLocation(String address) {
// Create a Uri from an intent string. Use the result to create
//an Intent.
Uri gmmIntentUri = Uri.parse("geo:" + address);
// Make the Intent explicit by setting the Google Maps
// package
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(mapIntent, REQUEST_LOCATION);
}
}
Here you can find an overview on how to use intents to start Google Maps with an Address:
https://developers.google.com/maps/documentation/urls/android-intents