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
Related
I have two values in latitude and longitude. I have a key. This button must have two options to go to location information,Yandex Navi and Google Maps. When I click on the button, I want to know which one would like to open it. How can I do that?
You can use Intent.createChooser() like:
String url = "yandexmaps://maps.yandex.ru/?pt=" + latitude + "" + longitude + "&z=12&l=map";
Intent intentYandex = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intentYandex.setPackage("ru.yandex.yandexmaps");
String uriGoogle = "geo:" + latitude + "," + longitude;
Intent intentGoogle = new Intent(Intent.ACTION_VIEW, Uri.parse(uriGoogle));
intentGoogle.setPackage("com.google.android.apps.maps");
String title = "Select";
Intent chooserIntent = Intent.createChooser(intentGoogle, title);
Intent[] arr = new Intent[1];
arr[0] = intentYandex;
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arr);
startActivity(chooserIntent);
Andrii Omelchenko's answer always opens Google Maps for me. But after change google and Yandex order for chooserIntent, it is worked in my case:
val uriYandex = "yandexnavi://build_route_on_map?lat_to=${latitude}&lon_to=${longitude}"
val intentYandex = Intent(Intent.ACTION_VIEW, Uri.parse(uriYandex))
intentYandex.setPackage("ru.yandex.yandexnavi")
val uriGoogle = Uri.parse("google.navigation:q=${latitude},${longitude}&mode=w")
val intentGoogle = Intent(Intent.ACTION_VIEW, uriGoogle)
intentGoogle.setPackage("com.google.android.apps.maps")
val chooserIntent = Intent.createChooser(intentYandex, title)
val arr = arrayOfNulls<Intent>(1)
arr[0] = intentGoogle
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arr)
val activities = packageManager.queryIntentActivities(chooserIntent, 0)
if(activities.size>0){
startActivity(chooserIntent)
}else{
//do sth..
}
If it absolutely has to be either Google Maps or Yandex Navi, the easiest way would probably be to figure out which one the user wants to use (via a dialogue or similar), and then set that as the target of a Map Intent. For example, here's an intent from Google's Android documentation that targets Google Maps by app name:
// Creates an Intent that will load a map of San Francisco
Uri gmmIntentUri = Uri.parse("geo:37.7749,-122.4194");
Intent mapIntent = new Intent(Intent.ACTION_VIEW,
gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
This should also work with Navi by setting the package to "ru.yandex.yandexnavi".
Note, though, that a more standard way to do this would be with a Map Intent that doesn't specify the targeted app. That way, all you would have to provide is the coordinates, and then the user could use their app of choice:
public void showMap(Uri geoLocation) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(geoLocation);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
I have tried by this way but it does not navigate Automatically to this point.
String uri = "http://maps.google.com/maps?saddr="+"22.541035,88.356366"+"&daddr="+"22.541251,88.347414";
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);
Try this function
public static void showRouteOnMap(Context mContext, String lat, String lng) {
Uri gmmIntentUri = Uri.parse("google.navigation:q=" + lat + "," + lng);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
mContext.startActivity(mapIntent);
}
Pass latitude and longitude of the destination location.
Your can you this it will draw route on google map from your current location you can change it as you want
private void googleMapDirectionIntent(String destination) {
Uri.Builder directionsBuilder = new Uri.Builder()
.scheme("https")
.authority("www.google.com")
.appendPath("maps")
.appendPath("dir")
.appendPath("")
.appendQueryParameter("api", "1")
.appendQueryParameter("destination", "" + destination);
startActivity(new Intent(Intent.ACTION_VIEW, directionsBuilder.build()));
}
Hope it Helps.
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);
I can set my end point here. How can I set the start point with it?
Uri gmmIntentUri = Uri.parse("google.navigation:q=Taronga+Zoo,+Sydney+Australia");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Google launched new API: Google Maps URLs
https://developers.google.com/maps/documentation/urls/guide
This API allows to create
a universal, cross-platform URL to launch Google Maps and perform searches, get directions and navigation, and display map views and panoramic images.
From now on you can use something like
Uri gmmIntentUri = Uri.parse("https://www.google.com/maps/dir/?api=1&origin=Space+Needle+Seattle+WA&destination=Pike+Place+Market+Seattle+WA&dir_action=navigate");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Hope this helps!
use below snippet:
String uri = "http://maps.google.com/maps?hl=en&saddr=" + currentlatLng.latitude + "," + currentlatLng.longitude + "&daddr=" + destination.latitude + "," + destination.longitude+ "&mode=driving";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivityForResult(intent, Constants.REQUEST_OPEN_GOOGLE_MAP);
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);