Not able to open directions in google map in android - android

I have one screen in app which shows address. Now I want to open google when while click on that address. And it have to show directions from current location to that address.
//code in app
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?daddr=28.5600697,77.2695753"));
startActivity(intent);
but it is not opening location only processing.

Try this
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?q=28.5600697,77.2695753"));
startActivity(intent);
and please let me know if it works.

Try something like this. this will Suppress chooser dialog when calling Google map using intent
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+Latitude+","+Longitude+"&daddr="+latitude+","+longitude));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);

Try this code
float storeLatitude = Float.parseFloat(storeList.latitude + "");
float storeLongitude = Float.parseFloat(storeList.longitude + "");
String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?daddr=%f,%f (%s)", storeLatitude, storeLongitude, "Store Address");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);

First you need to fetch user's current Latitude and Longitude than use following :
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" + mUserLatitude + ", " + mUserLongitude +
"&daddr=" + lat + ", " + lon));
startActivity(intent);
Where lat , lon is destination Latitude and Longitude resepectively.

Related

How to add pin point on Google Map using package (when you click on a button, it open directly to Google Map App) on android studio

I have trouble with adding the pin point on Google Map using package for opening Google Map App to show the point of location on android studio. Here is the code
Uri gmmIntentUri = Uri.parse("geo:"+29.972653+","+31.283936);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<" + latitude + ">,<" + longitude + ">?q=<" + latitude + ">,<" + longitude()));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
try {
context.startActivity(intent);
} catch (ActivityNotFoundException ex) {
String urlAddress = "http://maps.google.com/maps?q=" + latitude + "," + longitude;
Intent intents = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress));
context.startActivity(intents);
}
It will check if GoogleMaps application is installed or not and if not then redirect you to browser
Try this:
String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(mapIntent);

Google Maps 7 started with geo intent is dropping a pin at the closest address to a coordinate instead of the exact location

In my app users can save the latitude and longitude of a particular location. I want them to able to launch other apps on their phone via a geo intent such as Google Maps so that they can easily get exact directions back to it. Here is the code I am using to generate the geo intent:
public static Intent getFindIntent(Context context) {
Intent intent = new Intent();
SharedPreferences prefs = Tools.getPrefs(context);
String latitude = prefs.getString(Const.LAT_KEY, "");
String longitude = prefs.getString(Const.LONG_KEY, "");
intent.setAction(Intent.ACTION_VIEW);
String uri = String.format(Locale.US, "geo:%s,%s?z=%d&q=%s,%s", latitude, longitude,
Const.ZOOM_LEVEL, latitude, longitude);
intent.setData(Uri.parse(uri));
return intent;
}
Obviously most people will use Google Maps since it's on everyone's phone. When I first released my application Google Maps would start and drop a pin at the exact coordinates specified in the q parameter of the geo uri that is set as data for the intent. With the release of Google Maps 7, maps seems to drop a pin at the closest address to the provided coordinates. This poses a problem to me since users should be able to navigate back to the saved position exactly, and not an address near it. The only place I have found this documented is here. The docs are from the official Android Developer site but they are very sparse. Are there alternatives to the geo intent to provide this functionality or is there something wrong with my code? I think Google Maps is breaking it's API contract since I am providing coordinates and not an address.
To drop the pin use this code:
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 directions use this :
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" + lat
+ "," + lng + "&daddr="
+ AppointmentDetailLayout.docLatitude + ","
+ AppointmentDetailLayout.docLongitude));
context.startActivity(intent);

google maps application from my application wid a label over the location

I can open google maps from my application and have a pointer over the location i am pointing to.
Instead i wanted to open google maps application from my application---- as is when user clicks on an address google maps application opens up with that particular point.
for that i used
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("geo:lat,lng?q=lat,lng")));
Here lat=34.456373 and lng=-45.464748
Google maps application is opening but that particular location is not coming up instead my present location is coming up.How to rectify that?
String geoCode = "geo:0,0?q=" + PLACE_LATITUDE + ","+ PLACE_LONGITUDE + "(" + PLACE_NAME + ")";
Intent sendLocationToMap = new Intent(Intent.ACTION_VIEW,
Uri.parse(geoCode));
startActivity(sendLocationToMap);
http://developer.android.com/guide/appendix/g-app-intents.html refer for more detail..
String uri = String.format("geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);
see if this helps.
lat.setText(String.valueOf(latitude));
lon.setText(String.valueOf(longitude));
String showMap = String.valueOf(latitude) + ","
+ String.valueOf(longitude);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:0,0?q=" + (showMap)));
try {
startActivity(intent);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Error in gps "+e, Toast.LENGTH_LONG).show();
}

Search nearby hospital via google map intent (Android)

I need to search nearby child hospital and find the root from button click using intent,
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?&saddr="
+ x
+ ","
+ y
+ "&daddr=nearby child hospitals"
));
startActivity(intent);
x,y as current lat and long.
It will show the hospitals are not in my current location(Shows different country hospitals)
Then, I click back button, then click Get Directions button means (From text box contains my source lat and long, Destinations text box contains nearby child hospitals), it shows my nearer child hospitals.
Is there any way do to this in first (i.e., intent call)?
You can use "geo:" URL scheme to open maps and then search nearby hospitals like this:
String uri = "geo:"+ x + "," + y +"&q=child hospitals";
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
For documentation reference, see Invoking Google Applications on Android Devices
Uri gmmIntentUri = Uri.parse("geo:0,0?q=" + query);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(gmmIntentUri.toString()));
intent.setPackage("com.google.android.apps.maps");
try {
context.startActivity(intent);
} catch (ActivityNotFoundException ex) {
try {
Intent unrestrictedIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(gmmIntentUri.toString()));
context.startActivity(unrestrictedIntent);
} catch (ActivityNotFoundException innerEx) {
Toast.makeText(context, "Please install a maps application", Toast.LENGTH_LONG).show();
}
}
you can use this code, intent open a map and automatic search hospital near me
String uri = "geo:"+ x + "," + y +"?q=hospitals+near+me";
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));

Suppress chooser dialog when calling Google map using intent

I want to call google map intent without showing "Complete Action Dialog"?
Is it possible? Here is my code.
String uri = "http://maps.google.com/maps?saddr=" + Utils.getLatitude(ShowDetails.this)+","+Utils.getLongitude(ShowDetails.this)+"&daddr="+userLatitude+","+userLongitude;
startActivity(new Intent(android.content.Intent.ACTION_DEFAULT, Uri.parse(uri)));
I dont want to show below dialog when calling google map intent . Any Help is appreciated .
Below code helps me to solve my question.
String uri = "http://maps.google.com/maps?saddr=" + Utils.getLatitude(ShowDetails.this)+","+Utils.getLongitude(ShowDetails.this)+"&daddr="+userLatitude+","+userLongitude;
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);
Use the Google Maps URI rather than "http://[...] "
It goes something like this:
String uri = "geo:" + latitude + "," + longitude
Check out http://developer.android.com/guide/appendix/g-app-intents.html for the info.
Try ACTION_VIEW instead of ACTION_DEFAULT:
String uri = "geo:"+ latitude + "," + longitude;
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
check this Android doc Intents List and browse to "Google Maps".

Categories

Resources