Suppress chooser dialog when calling Google map using intent - android

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".

Related

Not able to open directions in google map in 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.

Android google maps intent zooms too far

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);

Show Location in Google Maps in Android

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

Intent to Google Navigation for itinerary with several waypoints

I want to know, if it's possible to put several "checkpoints" within "Google Navigation" (Google Maps Navigation) With a query that follows the next syntax : "google.navigation:q=44.871709,-0.505704...."
If it possible, what is the syntax for separate two points ?
For one point it works, example : "google.navigation:q=44.871709,-0.505704"
But I would put a few checkpoints for example :
LatLng point1 = new LatLng(44.871709,-0.505704);
LatLng point2 = new LatLng(43.572665,3.871447);
Intent(android.content.Intent.ACTION_VIEW,Uri.parse("google.navigation:q="+
point1.latitude+","+point1.longitude+";"+ point2.latitude+","+point2.longitude));
I read others issues, they say to use this syntax :
"http://maps.google.com/maps?saddr="+"44.871709,-0.505704"+"&daddr="+"43.572665,3.871447"
With above solution, "Google Navigation" is not started automatically, we must choose one application "Google Maps" and next, to click on Itinerary (in top of the screen) to start "Google Navigation".
I would like to avoid it if possible.
Here is a way to supress the dialog and go to maps directly.
String uri = "http://maps.google.com/maps?saddr="+"44.871709,-0.505704"+"&daddr="+"43.572665,3.871447";
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);
Let me know if you still have issues.
UPDATE
As of May 2017, there is a better approach, the Google Maps URLs API
https://developers.google.com/maps/documentation/urls/guide
Using this API you can construct an URL with origin, destination and waypoints and pass it to the intent
String uri = "https://www.google.com/maps/dir/?api=1&origin=Madrid,Spain&destination=Barcelona,Spain&waypoints=Zaragoza,Spain%7CHuesca,Spain&travelmode=driving&dir_action=navigate";
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);
Check these 2 methods, both of them work properly for me.
METHOD 1:
String packageName = "com.google.android.apps.maps";
String query = "google.navigation:q=49.4839509,8.4903999";
Intent intent = this.getPackageManager().getLaunchIntentForPackage(packageName);
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(query));
startActivity(intent);
METHOD 2:
String packageName = "com.google.android.apps.maps";
String query = "google.navigation:q=49.4839509,8.4903999";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(query));
intent.setPackage(packageName);
startActivity(intent);
Because point1.longitude is Double,you should use this
String.valueOf(point1.latitude);
Intent(android.content.Intent.ACTION_VIEW,Uri.parse("google.navigation:q="+String.valueOf(point1.latitude)+","+String.valueOf(point1.longitude)+";"+String.valueOf( point2.latitude)+","+String.valueOf(point2.longitude)));
Or you can use this,but it is just the same.
point1.toString().replace("lat/lng: (", "").replace(")", "")
point1.toString() the result is "lat/lng: (44.871709,-0.505704)",remove the "lat/lng: (" and ")".
then you can get the result that you want.
Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+point1.toString().replace("lat/lng: (", "").replace(")", "")+"&daddr="+point2.toString().replace("lat/lng: (", "").replace(")", "")));
Or you can try this
Uri uri = Uri.parse("http://maps.google.com/mapssaddr="+point1.toString().replace("lat/lng: (", "").replace(")", "")+"&daddr="+point2.toString().replace("lat/lng: (", "").replace(")", ""));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
I hope this can help you.
You have to just pass destination location. Google Maps app will automatically take your current location for navigation.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + String.valueOf(destination latitude)
+ "," + String.valueOf(destination longitude)));
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();
}

Categories

Resources