3

I have a google maps place defined by their place_id s.

The place can refer to:

  • an address, eg 221B Baker St, Marylebone, London NW1 6XE, UK : ChIJFbp6NM8adkgRdOYUaV-EQlw
  • Or a general area eg London NW1, UK: ChIJoZM_S7EadkgR_T2MfOBVirE

I would like to know, using google maps API, whether a given address is inside the previous area or near the previously defined address (distance can be defined as a birth flight distance from the previous place).

Majid Laissi
  • 19,188
  • 19
  • 68
  • 105
  • Not sure what exactly the question is. – Rob Jul 19 '17 at 18:22
  • how to know if an address is inside an area referenced by the place_id. Or how to measure the distance between an address and a place_id. – Majid Laissi Jul 19 '17 at 18:59
  • 2
    There is an open feature request, https://issuetracker.google.com/35816953, to return the polygon of areas such as cities, postal codes, etc. Using this, you could determine if the lat/lng of the address is inside the polygon. I suggest starring that issue. As far as determining how far addresses are away from each other as the crow flies, you could get the lat/lng of each and use an algorithm to determine the distance between coordinate pairs, such as http://www.movable-type.co.uk/scripts/latlong.html – Rob Jul 20 '17 at 17:57
  • Thank you. I am using now the "bounds" property for a given place which is not accurate at all (allways a rectangle). For the distance i will use the algorithm even though it's not accurate for small distances. But it's good enough for my use case. Thanks – Majid Laissi Jul 20 '17 at 18:00

1 Answers1

1

You can use place IDs as origins and destinations in the Google Distance Matrix API. So, you can use your place ID as an origin and the address you want to test as the destination. Call the API to determine the distance. I think this was an update in 2017 maybe, see: https://developers.google.com/maps/documentation/distance-matrix/intro#RequestParameters

Art
  • 141
  • 1
  • 5