5

If I have two placeid's, my address and the country, how can I ask Google Maps API if my address' placeid is inside the country's placeid?

For example, the white house has a placeid of ChIJ37HL3ry3t4kRv3YLbdhpWXE and USA has a placeid of ChIJCzYy5IS16lQRQrfeQ5K5Oxw, can Maps API tell me if the white house is in the USA using the placeid's? If so, how?

If I go to https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJCzYy5IS16lQRQrfeQ5K5Oxw&key=REDACTED then I can see the full details of a placeid but this doesn't tell me what I need to know.

Hooli
  • 1,135
  • 3
  • 19
  • 46
  • Possible duplicate of [Get place\_id of address\_components](https://stackoverflow.com/questions/43499392/get-place-id-of-address-components) – Gajus May 28 '19 at 21:04

1 Answers1

3

Google Maps API doesn't expose any endpoint capable to check the relationship between place IDs.

The unique option you have is checking the address components of one place ID and try to figure out if they contain address components of another place ID. In other words find an intersection of address components.

Please look at these requests:

https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJCzYy5IS16lQRQrfeQ5K5Oxw&key=YOUR_API_KEY

https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJ37HL3ry3t4kRv3YLbdhpWXE&key=YOUR_API_KEY

You can see that they contain a common address component

{
    "long_name":"United States",
    "short_name":"US",
    "types":[
        "country","political"
    ]
}  
xomena
  • 31,125
  • 6
  • 88
  • 117
  • Having Place IDs in the address_components array would help, no? Feel free to file a feature request at https://code.google.com/p/gmaps-api-issues/issues/entry?template=Geocoding%20API%20-%20Feature%20Request – miguev Jun 13 '16 at 08:10
  • A feature request to expose place ID of each address component is already created: https://issuetracker.google.com/issues/35827596 – xomena Oct 16 '18 at 17:03