问题
I'm working on a google map application. I am drawing a polygon on GMap and getting the area covered by it. I need to find out how many zipcodes are there inside the covered area. How can I proceed using google maps API? Any suggestion?
回答1:
You'll need, as david strachan said, the geometry for each ZIP-code, here is such an database: https://www.google.com/fusiontables/DataSource?docid=1AxB511DayCdtmyBuYOIPHIe_WM9iG87Q3jKh6EQ#rows:id=1
use a database that supports geospatial queries and query the database by using ST_CONTAINS and ST_INTERSECTS
Note: The linked database is a FusionTable, it will give you the geometry, but you must store these data in another database , because FusionTables did not support Polygons for spatial conditions
回答2:
Was apparently too late :) But would provide a serious answer, and that can take some time when you also have a dayjob. Note : Dr. Molles fusiontable does only cover <65% or so, of all US zipcodes. As I comment, it is very reduced and therefore maybe not so good for finding zipcodes for local distributors.
The promised answer :
See this working demo which extracts all zipcodes of any polygon on a US map -> http://bit.ly/1cW1am6
I found this zipcode-database -> http://www.boutell.com/zipcodes/ which contain all US zipcodes along their centered latlngs - the before mentioned http://federalgovernmentzipcodes.us/ was lacking 1000 zipcodes and a lot of latlng-info was missing.
Zoom in, create a polygon by clicking and hit search :

The code works like this :
- pass the polygon as [lat,lng] pairs to the server by ajax
- create a preliminar square describing the boundaries
- search all zipcodes inside the square
- use a Point in Polygon algorithm to refine the search
- deliver back the zipcodes inside the polygon
Below the google map there is link to a zipfile containing the complete demo, that is full sourcecode and databasedumps (as well as original CSV-files). I had planned to desribe the code in details, but the question does already have an accepted answer - and I have already spent a lot of time on this demo. Note : The demo will some day eventually be deleted from the server.
回答3:
I think this is what you need: US Zipcode Boundaries API: https://www.mashape.com/vanitysoft/boundaries-io
Above API shows US Boundaries(GeoJson) by zipcode,city, and state. you should use the API programatically to handle large results.
for example:


来源:https://stackoverflow.com/questions/19424185/find-zipcodes-inside-polygon-shape-using-google-maps-api