Android: Open Google Map (Fragment inside my app) with traffic detail - android

I want to display all traffic detail within my app on Map fragment
As for now I'm using google intent
Uri gmmIntentUri = Uri.parse
("geo:0,0?z=15&q=traffic+on+map");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
For map fragment I am referring this
https://developers.google.com/maps/documentation/android/map
How do I enable traffic layer on this?

You want to display traffic layer on your Google map fragment
use your googleMap object and
googleMap.setTrafficEnabled(true);
for ref
https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap#setTrafficEnabled(boolean)

Related

Intent For opening google maps with specific search text

I'm creating a local guide app on android, and I want to set an onItemClickListener to my array that will open google maps with filled search text. For example: In shopping category, there are stores like ZARA H&M. So, I want to create an Intent that will open google maps with search text "ZARA near me" etc.
Can anyone help me with it?
Thanks in advance.
You can pass the lat, lon of the area you are interested like so:
// Search for restaurants in San Francisco
Uri gmmIntentUri = Uri.parse("geo:37.7749,-122.4194?q=restaurants");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Or by address like so:
Uri gmmIntentUri = Uri.parse("geo:0,0?q=1600 Amphitheatre Parkway, Mountain+View, California");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Taken from the Google docs.

intent for direct turn by turn navigation on google maps along with mode of transit

My google maps intent code, It works and I have used this because I don't want to click the start button, this intent takes me to the turn by turn navigation:
Uri gmmIntentUri =
Uri.parse("google.navigation:q=22.5850383,88.3425874");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri); mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
I want to specify the mode of transit as 'driving', I have tired
Uri.parse("google.navigation:q=22.5850383,88.3425874&mode=driving");
but it's not working.how do I specify transit mode as driving in the intent code
There are certain parameters you can supply via the navigation intent
Query
q: Sets the end point for navigation searches. This can be a latitude,longitude or a query formatted address. If it is a query
string that returns more than one result, the first result will be
selected.
Mode mode sets the method of transportation. Mode is optional, defaults to driving, and can be set to one of:
d for driving
w for walking
b for bicycling
Avoid avoid sets features the route should try to avoid. Avoid is optional and can be set to one or more of:
t for tolls
h for highways
f for ferries
Example
Uri gmmIntentUri = Uri.parse("google.navigation:q=22.5850383,88.3425874&mode=d");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
I think you have to append &mode=d to the uri instead of &mode=driving
Documentation
https://developers.google.com/maps/documentation/urls/android-intents

Is it possible to intent navigation 2 more points in google maps android?

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);
It code for 2 points and what about if it will 20 points?
As I know Google Maps recommends 23 points
enter image description here
You can now use the Google Maps URLs API launched by Google in May 2017.
https://developers.google.com/maps/documentation/urls/guide
Using this API you can construct navigation URL and specify waypoints in addition to origin and destination.
So the sample code might be something like
Uri gmmIntentUri = Uri.parse("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 mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
I hope this helps!

How to launch route activity on google maps without destination

How can I launch route activity on google maps from my app without specifying the destination? I am using:
Uri gmmIntentUri = Uri.parse("google.navigation:q=<>");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Bad behavior :
But the "to" field in google maps has "<>" string, and if I write:
Uri gmmIntentUri = Uri.parse("google.navigation:q=");
But this not working.
The idea is:
Right behavior:
There doesn't seem to be a way for you to specifically go to a specific Activity in the official Maps app (empty destinations). If you look at the Google Maps Intent, it exposes several intents that can launch Maps to display, search, navigate and use Street View. For searching location, you are required to have coordinates or optional queries and labels.

How do I get the coordinates(latitude and longitude) that are saved in mysql and show them in maps as markers?

How do I get the coordinates(latitude and longitude) that are saved in mysql and show them in maps as markers? I have already set up a connection and it is working. Only problem is showing them in a map, rest all procedures are fine.
If you managed to retrieve coordinate data from the database and you have all the coordinates available when your map is ready, you can use GoogleMap#addMarker.
If you don't have the coordinates, please post what you have done so far.
Edit: How to open Google Maps with specific location
If your goal is to open Google Maps with specific location, then you can use geo:latitude,longitude?z=zoom Uri for your Intent.
Example code:
// 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);

Categories

Resources