activating layers in google maps programmatically - android

From my app, I currently invoke google map using this:
Uri uri = Uri.parse("geo:" + "45.420833" + "," + "-75.69?z=13");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
I need to turn on the traffic layer upon launching the intent.
I couldn't find any simple way to do so online. I couldn't find an extra parameter to do so either :(
Any idea?

Altough I have not tried it yet, this might work for you if you are using a mapView within the app:
mapView.setTraffic(true);

I need to turn on the traffic layer upon launching the intent.
You will have to embed MapView for that, AFAIK.

Related

Launching Huawei Petal Maps Directions via Intent on Android

Is it possible to launch Huawei Petal Maps with navigation from point A to point B using intent just like in google maps? If yes, how?
Yes, you can use an intent to launch the Petal Map app, and then use navigation functions in the app.
Deep link example:
mapapp://navigation?saddr=xxx&daddr=xxx&language=xx&type=xxx
mapapp://navigation?saddr=home&daddr=company&language=en&type=drive
mapapp://navigation?type=exit
To use this function, you need to set uriString to the following:
"mapapp://navigation?saddr=25.102916,55.165363&daddr=25.164610000000,55.228869000000&language=en&type=drive"
Sample code after modification:
String uriString = "mapapp://navigation?saddr=25.102916,55.165363&daddr=25.164610000000,55.228869000000&language=en&type=drive";
Uri content_url = Uri.parse(uriString);
Intent intent = new Intent(Intent.ACTION_VIEW, content_url);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
For more details, see docs.
As it would seem from this link, India is currently not among the supported regions for Huawei Petal Map. Currently, you would not be able to use it for navigation.

set From location to current location in google maps android programmatically

I am creating an app where it requires opening google maps to navigate to a place in walking mode and to set source/from location to current location.
Here is the code I use.
String url = "https://maps.google.co.in/maps?q=" + destination + "&mode=walking";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
How do I set "From location" to "current location"??
Thanks.
I would suggest using a Google Maps URLs instead of the link you provided in the example. The Google Maps URLs is an official and recommended way to launch Google Maps app on mobile devices and web browsers.
Please note that if you omit the origin parameter in the Google Maps URLs, the API will use your current location if available
origin: Defines the starting point from which to display directions. Defaults to most relevant starting location, such as user location, if available. If none, the resulting map may provide a blank form to allow a user to enter the origin. The value can be either a place name, address, or comma-separated latitude/longitude coordinates. A string should be URL-escaped.
So, you should rewrite your code as
String url = "https://www.google.com/maps/dir/?api=1&destination=" + destination + "&travelmode=walking&dir_action=navigate";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
I hope this helps!

Navigation with Waze and Google Maps using Intent.createChooser shows Waze icon twice

I'm creating this question after finding the answer, I was not sure about the etiquette, but it seems to be OK (plus, I see now there's a built-in option).
The problem was as described in the title, we created an intent chooser using code that resembles this:
String url = "waze://?ll=" + latitude + ", " + longitude + "&navigate=yes";
Intent intentWaze = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
String uriGoogle = "google.navigation:q=" + latitude + "," + longitude;
Intent intentGoogleNav = new Intent(Intent.ACTION_VIEW, Uri.parse(uriGoogle));
String title = context.getString(R.string.title);
Intent chooserIntent = Intent.createChooser(intentGoogleNav, title);
Intent[] arr = new Intent[1];
arr[0] = intentWaze;
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arr);
context.startActivity(chooserIntent);
And got two Waze icons and one Google Maps icon; and worse, one of the Waze icons did not start the navigation (only open the app).
We could not use the geo: intent because we need to control the intents shown (we don't want to show both intents at all times) and the navigation type in Google Maps (for example: &mode=w).
After some time I used the solution found here, and there was only one icon that was working properly. As I wrote in the question, I could not use this solution because it lacks the flexibility I needed, so after looking at the code I saw that what was missing was this:
intentWaze.setPackage("com.waze");
// and more importantly, this:
intentGoogleNav.setPackage("com.google.android.apps.maps");
It seems that Waze is listening to the Google Maps intent (and does not work well with it), and that's why there were two icons.

Uri throwing Uber Intent

I am developing a geo located based app, and I have an option : "Show me the way" that should show the map and how to get there, so far is working with google maps, and also with Waze, the Uber app is showing in the App selector to open the action (Intent) that I'm throwing from the app, but it does not work with the data is receivng, so What additional data should I send? I was reading the Uber official documentation but it's more for web and URL based calls and I haven't found an example with the "geo" tag Intent that I'm using and works for other apps.
The code I am using to throw the Intent is this:
case R.id.menu_ride:
{
String uri = "geo: "+newPlace.getLatitude()+","+newPlace.getLongitude();
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
return true;
}
I don't know if it is the right way to do it but this is the way I am using it and it's working on Google Maps, Uber and Waze with no problems:
case R.id.menu_ride:
{
String uri = "geo: "+newPlace.getLatitude()+","+newPlace.getLongitude() +
"?q="+newPlace.getLatitude()+","+newPlace.getLongitude() ;
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
return true;
}
Seeems like you had to add the GET parameter "q" for the query.

Draw route on map without MapActivity

I want to draw a path on map between known points(lat, long) using:
String uri = "http://maps.google.com/maps?f=d&hl=en&saddr="+source_latitude+","+source_longitude+"&daddr="+destination_latitude+","+destination_longitude;
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);
But instead of just drawing route, Google Maps shows menu Car/Bus/By foot, trying to make a route from my current location to those points. What am I doing wrong? Is it still possible to draw route on map using the method above?
By running this intent you are basically opening an "outside" application - Google Maps that is not related to your application. the behavior you are receiving is the behavior that should be for the version of Google Maps you have in your phone. You can't edit the way it behaves, only the things that you are allowed to change using the settings screen of this application.
You have to parse the xml or json that your are using in the url in an Asynctask class and draw it on the map.

Categories

Resources