0

I have a list of PlaceIds from Google Maps that I got from querying an external list of location names.

I now have a "search" feature where you enter your zip code, and it finds the closest 10 locations and shows them on a map. As far as I can tell, Google only lets you search by a search term.

How do I limit my search results only to the list of PlaceIds that I have present, and order it by distance?

NOTE: I don't have a "keyword" to search for that will include all my PlaceIds. These were retrieved from an external source, and there is no "common search keyword" that will return a super-set of my PlaceIds.

1 Answers1

1

Restricting the results of a PlacesSearch in that way currently is not possible.

Possible approach:

You'll also need a Database of ZIP-Codes(including the locations).

When your DB supports spatial queries you may use ST_DISTANCE() to order the results and use the 10 nearest results.

When your DB doesn't support spatial queries you may use the haversine formula to calculate the distance

Of course the result may only be approximate, because a ZIP-code usually is related to an area, not to a location

Community
  • 1
  • 1
Dr.Molle
  • 116,463
  • 16
  • 195
  • 201