Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Zip code boundaries in Google Map API

I have seen all the responses to a similar question, however, they are all either old, or no one has answered them.

I have been given the task to obtain zip codes and display their corresponding boundaries to the user on a Google map, like in this example.

I am writing this code in Javascript and using the Google Maps API. I want the user to input a zip code and a marker drops down on their destination with a border representing that zip code area. I see that Google Maps currently has something in their map code that allows one to see the boundaries if someone puts a zip code on maps.google.com. I have used polygons but this wouldn't help make a border around a certain zip code.

Any suggestions on how to obtain this?

Thanks in advance!

like image 816
njavia66 Avatar asked Jul 13 '12 13:07

njavia66


People also ask

How do I show boundaries based on ZIP codes on Google Maps?

To see it yourself, go to Google Maps and search for a city name or even a zip code. You will see a pinkish highlight around the border. Based on your zoom level, as you zoom out, Google will highlight the whole area, not just the borders, in the pink color.

How do I limit areas on Google Maps?

Step 1 Go to Add or Edit Map and scroll down to 'Limit Panning Settings' section. Step 2 Enable 'Limit Panning' tab. Step 3 Enter latitude and longtitude of south and north west and select any zoom level. Step 4 At the end, click on the Save Map.


1 Answers

There is not an easy answer to this that I know of. But here is a high level design of how to do it.

All of the shape files for zip codes can be found at the census site and can be downloaded from this ftp server. However, that's a ton of data, so you need a place to store it. I recommend using the PostgreSQL database with the PostGIS add on. It is free and open source and generally awesome. It has a utility for converting .shp files (the type in the census shape files) into PostGIS geometry form. PostGIS let's you retrieve the shapes back out as KML.

You can either a) retrieve a shape from the database as KML when it is needed and display it on the map or b) pre-generate a kml file for every zip code ahead of time and retrieve a file as it is needed (this would take up quite a bit of space).

like image 51
Mark Avatar answered Oct 21 '22 12:10

Mark