Is It Possible To Open Google Maps By PlaceId?

2020-07-17 14:45发布

问题:

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

  1. 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 ?

  2. 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)

回答1:

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!



回答2:

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