Is It Possible To Open Google Maps By PlaceId? - android

I have a place id obtained from Google Places API, and the aim is opening Google Maps app via place id like similar approach of below
Uri gmmIntentUri = Uri.parse(String.format(Locale.ENGLISH,"geo:%f,%f", lat, lon));
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mapIntent);
}
Is there a way for this ?
I have already latitude, longitude when user type for example "Eiffel Tower" from places API. And I'm storing those values for next usages(Say we are listing some sort of visited places from local database, and user click one of them and app navigates to Google Maps)
I have a few concerns
If i use latitude-longitude to indicate a place instead of place id
on Google Maps, what will happen if "Cafe XYZ" moved another street
?
If i use place id each time to receive last location of "Cafe XYZ"
(instead of stored values in my local database) the app easily hit request limits
So those concerns made me think a way that just sending place id Google Maps(like sending coordinates)

Indeed, there is a way to open Google Maps app with a place ID. For this purpose you have to use Google Maps URLs that was launched in May 2017. Following the documentation of Google Maps URLs you can construct the following URL for "Eiffel Tower" (place ID ChIJLU7jZClu5kcR4PcOOO6p3I0)
https://www.google.com/maps/search/?api=1&query=Eiffel%20Tower&query_place_id=ChIJLU7jZClu5kcR4PcOOO6p3I0
So, your code will be something like
Uri gmmIntentUri = Uri.parse("https://www.google.com/maps/search/?api=1&query=Eiffel%20Tower&query_place_id=ChIJLU7jZClu5kcR4PcOOO6p3I0");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mapIntent);
}
I hope this helps!

It's probably super late but I was able to make it work with info we should have aside from the LatLog
Searching for CenturyLink Field using latitude/longitude coordinates as well as the place ID results in the following map:
https://www.google.com/maps/search/?api=1&query=47.5951518,-122.3316393&query_place_id=ChIJKxjxuaNqkFQR3CK6O1HNNqY

Related

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!

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.

Android Map search for an address

In my Android application I am working with Google Maps, where I want to search for a particular address for example "Apple Office". So I found the current location and need to search for "Apple Office" within five km of the current position. So my address is already marked in Google Maps. I know how to search for a location
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);
}
This will search for San Francisco... but I need to search with text. So what change do I need for that?
You have to use 'Google Places API for Android'. https://developers.google.com/places/android-api/

How to open the shortest path of google map navigation in android?

I'm opening a google map using my android program. I did it with the following URL,
http://maps.google.com/maps? saddr=31.186371,121.489885&daddr=31.249351,121.45905&mode=driving
But this opens a view like,
I want to open the shortest path(1st one in list view) from these paths. Is there a way to do this? How may I do this?
According to the documentation, you can launch the turn by turn navigation by this intent:
google.navigation:q=a+street+address
you can use these code to launch the intent:
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);
As you might able to tell, this can only give a turn-by-turn direction from current location to point A, but not point A to point B. You should consider using the web direction API and draw the polyline on your own Google Maps to gain more controls.

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