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)
Using Swift 5 and XCode 13, I was able to use Google's Universal cross-platform syntax to open Google Maps app in directions mode. The link will open the google maps app if it is installed on the phone. If maps is not installed it will open the url in the browser.
On your computer, open Google Maps. Go to the directions, map, or Street View image you want to share. Select Share or embed map. If you don't see this option, click Link to this map.
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)
As far as I can determine, you can't search by placeId on the regular google maps, but the embed version does allow it, by prefixing the placeId with place_id: in the search. Place Ids can be found with this tool. Thanks for contributing an answer to Stack Overflow!
Notice: On March 30, 2022, all Google Maps Platform APIs will stop accepting certain obsolete place IDs . Beginning on March 30, 2022, any requests made using obsolete place IDs will be rejected, and return error code INVALID_REQUEST .
You can use the same place ID across the Places API and a number of Google Maps Platform APIs. For example, you can use the same place ID to reference a place in the Places API, the Maps JavaScript API , the Geocoding API , the Maps Embed API and the Roads API.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With