Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if one placeid is within another placeid

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.

like image 450
Hooli Avatar asked Oct 18 '22 08:10

Hooli


1 Answers

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"
    ]
}  
like image 85
xomena Avatar answered Oct 22 '22 01:10

xomena