[GIS] Zip code highlighting in Google Maps

google mapsgoogle-maps-apipolygonzip-codes

When we search for a zip code in Google Maps we get the area highlighted in the map with a dotted border.

How is this calculated?

How do they know how to draw the polygon?

I'm looking at implementing something equivalent, an overlay on each zip code of the visible area of the map.

Best Answer

I am not entirely sure if you are asking about implementation hints (I can't help you there) or more specifically about the zip code boundaries.

In any case, the Census Bureau provides so-called zip code tabulation areas which are polygonic approximations of zip codes. I say approximations because zip codes are really points on a map and may not conform to neat boundaries as typically seen on a map. Nonetheless, they provide the approximation, pretending they are areas. So, to your question, Google presumably translates the address to lat/longs, then checks for spatial membership in any number of 'neighborhood' layers, including neighborhood proper, zip code, probably others. If you searched for a specific zip code, their parser recognizes that as such and returns the corresponding feature from the tabulation area shapefile, and returns the corresponding polygon.

Zip code tabulation areas can be fetched here: ftp://ftp2.census.gov/geo/tiger/TIGER2014/ZCTA5/tl_2014_us_zcta510.zip