I\'m designing one application in which I want to show specific location on Map.
I\'m passing String
of address which is already placed on Google Map
You should 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);
And to drop a pin
try {
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("geo:" + AppointmentDetailLayout.docLatitude
+ "," + AppointmentDetailLayout.docLongitude
+ "?q=" + AppointmentDetailLayout.docLatitude
+ "," + AppointmentDetailLayout.docLongitude
+ "(" + label + ")"));
intent.setComponent(new ComponentName(
"com.google.android.apps.maps",
"com.google.android.maps.MapsActivity"));
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
try {
context.startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=com.google.android.apps.maps")));
} catch (android.content.ActivityNotFoundException anfe) {
context.startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id=com.google.android.apps.maps")));
}
e.printStackTrace();
}
For the ones, who are looking for opening the "Maps" app for a particular location(by passing lat and long) and do not want that lat/long co-ordinates to be shown in Maps search bar after redirection(Opening Maps app). Instead wish to show some label or place name, you can refer to the code below,
private void openMapView(String latitude , String longitude , String locationName){
Uri gmmIntentUri = Uri.parse("geo:"+latitude+","+longitude+"?q="+locationName);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(mapIntent);
}
}
Note : "locationName" in the method above, represents the name you wish to display inside the Maps search bar.
To show location and disply show directions button inside google Maps use this code snippet:
String geoUri = "http://maps.google.com/maps?q=loc:" + latitude + "," + longitude + " (" + locationName + ")";
Intent mapIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(geoUri));
if (mapIntent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(mapIntent);
http://maps.google.com/maps/api/geocode/json?address=" + address + "&sensor=false
String strUri = "http://maps.google.com/maps?q=loc:" + lat + "," + lng + " (" + "Label which you want" + ")";
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);
Thank you.
Uri gmmIntentUri = Uri.parse("geo:37.7749,-122.4194");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mapIntent);
}
Refer this documentation
try {
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" + src_lat+ "," + src_lng + "&daddr=" + des_lat + "," + des_lng));
startActivity(intent);
}catch (ActivityNotFoundException ane){
Toast.makeText(activity, "Please Install Google Maps ", Toast.LENGTH_LONG).show();
}catch (Exception ex){
ex.getMessage();
}
}
});