I am trying to fix a bug from QA team. When Android starts the intent to search for a specific address it zooms in too far(~200ft) Would like it set the distance further away around 1000ft Its like maps is ignoring the z param completely if I give it a query.
I have tried every way I can think of, even went thru google docs and tried this:
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);
But it still ignored the zoom level with address in there.
Here is my code now:
String geo = "geo:" +(mCampground.latitude + "," + mCampground.longitude);
String maplLabel =(mCampground.title);
String query =Uri.encode(mCampground.address1 + "(" + maplLabel+")");
String uriString = geo + "?q=" + query + "&z=10";
Uri uri = Uri.parse(uriString);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setPackage("com.google.android.apps.maps");
startExternalActivity(intent);
Related
I call Google Maps with an Intent like this:
Intent mapIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + lat + "," + lon + "&mode=d"));
mapIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Now I want to return to my app automatically when arriving at the destination. How can I achieve that?
Bonus question: Can I retrieve some information from Maps about the route like duration?
After i open google map activity with direction from my custom fragment it tend to terminate the whole app.
mapView.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+currlat+","+currLon+"&daddr="+destinationLat+","+destinationLon+"&travelmode=driving")));
in here mapView means my custome fragmnet.
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" + lastLocation.getLatitude() + "," + lastLocation.getLongitude() + "&daddr=" +
destinationLocationLatitude + "," +
destinationLocationLongitude));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
There is this example from the google developer doc where you use a geo: URI instead of an url
This URI works like this :
Use the geo: intent to display a map at a specified location and zoom level.
geo:latitude,longitude?z=zoom
Here is a code that uses it. Also, it ensures that Google Maps will receive it and not another app, and if Maps isn't installed, it just does nothing but you can add an else statement to tell the user that he needs Maps to execute the action
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);
}
To launch navigation, use google.navigation:q=latitude,longitude. The starting position will be the user current location. See this part of the google developer site
Uri gmmIntentUri = Uri.parse("google.navigation:q=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);
}
I want to start Google Maps and show the Location that are saved in String's
String street = projectItems.get(position).get(project_company_street);
String zip = projectItems.get(position).get(project_company_zip);
String city = projectItems.get(position).get(project_company_city);
I made something that doesn't meets my conditions.
Uri IntentUri = Uri.parse("google.navigation:q=" + street + "," + zip + "+" + city);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, IntentUri);
So if User presses the Button, Google Maps starts in Navigation Mode.
How can I just show the Location of it?
Hope my problem is clear.
Kind Regards!
Try to change your Uri to this:
Uri IntentUri = Uri.parse("geo:0,0?q=" + street + "," + zip + "+" + city);
You can achieve this by providing latitude and longitude of both current and destination locations like below
String sAddr = "http://maps.google.com/maps?saddr=%s,%s&daddr=%s,%s";
String sAddr2 = String.format(sAddr, cur_lat, cur_long, dest_lat, dest_long);
Uri gmmIntentUri = Uri.parse(sAddr2);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivityForResult(mapIntent, GoTo_MAP);
Please check below example :
Uri gmmIntentUri = Uri.parse("google.navigation:q=Taronga+Zoo,+Sydney+Australia&mode=b");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Ref : Google Navigation intent
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);
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".