Android - How to launch Google map intent in android app with certain location, zoom level and marker
Try the following solution:
double latitude = 40.714728;
double longitude = -73.998672;
String label = "ABC Label";
String uriBegin = "geo:" + latitude + "," + longitude;
String query = latitude + "," + longitude + "(" + label + ")";
String encodedQuery = Uri.encode(query);
String uriString = uriBegin + "?q=" + encodedQuery + "&z=16";
Uri uri = Uri.parse(uriString);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(intent);
Credit goes here: Answer
I believe the problem had to do with the spaces in your label. Encoding the query string will eliminate the issue by replacing the spaces with valid characters
google maps intent zooming to location of device
By following this documentation, you can use the geo:
intent to display the zoom level that you want.
geo:latitude,longitude?z=zoom
The z
parameter sets the initial zoom level of the map. Accepted values range from 0 (the whole world) to 21 (individual buildings).
Here is a example code that use zoom level equal to 10(z=10) that will attemp to find restaurant at a city level.
Uri gmmIntentUri = Uri.parse("geo:37.7749,-122.4194?z=10&q=restaurants");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Also check this SO question for more information.
How do I show a marker in Maps launched by geo URI Intent?
Try this:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?q=<lat>,<long>(Label+Name)"));
startActivity(intent);
You can omit (Label+Name) if you don't want a label, and it will choose one randomly based on the nearest street or other thing it thinks relevant.
How to Open and Directing Google Maps using Intent?
String strUri = "http://maps.google.com/maps?q=loc:" + latitude + "," + longitude + " (" + yourLocationName + ")";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(strUri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
Launching Google Maps Directions via an intent on Android
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);
To start the navigation from the current location, remove the saddr
parameter and value.
You can use an actual street address instead of latitude and longitude. However this will give the user a dialog to choose between opening it via browser or Google Maps.
This will fire up Google Maps in navigation mode directly:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("google.navigation:q=an+address+city"));
UPDATE
In May 2017 Google launched the new API for universal, cross-platform Google Maps URLs:
https://developers.google.com/maps/documentation/urls/guide
You can use Intents with the new API as well.
Related Topics
Android: Changing Nfc Settings (On/Off) Programmatically
How to Download a File from a Server and Save It in Specific Folder in Sd Card in Android
Include Stetho Only in the Debug Build Variant
Android Button Background Color
Android Audiotrack Playing .Wav File, Getting Only White Noise
How to Get the File *.Apk Location in Android Device
Android, Landscape Only Orientation
How to Get the Dreaded Write_Secure_Settings Permission for My Android App
Hax Kernel Module Is Not Installed
Auto Start Application After Boot Completed in Android
Communication Between Broadcastreceiver and Activity - Android
Getting Header from Response (Retrofit/Okhttp Client)
How to Change Action Bar Actions Dynamically
How to Detect Wifi Tethering State
How to Search for a Value in Firebase Android
How to Use Edittext Ontextchanged Event When I Press the Number