Reputation: 43
I am pretty new to the Google Maps API so looking for some advice. I am trying to make a dashboard which allows companies to set their availability zone using google maps and a radius around their location so say 5 miles.
I then want to be able to run a postcode lookup and return any companies who 'serve' the area covering that postcode.
So far I have reached a point where a company can drop a pin onto the map and place a radius around themselves but I have no idea where to go from there! I can pull the Longitude and Latitude of that radius but I'm not sure how I would handle the data from there really.
Like I say I am new to the Maps API so be nice and excuse my naivety sorry! :)
Upvotes: 0
Views: 178
Reputation: 5887
If you're wanting to do more than simple radius options, you'll need to look into representing Polygons in Google Maps. Since zip codes are often delineated by odd boundaries, it would be a requirement. If you obtain and store them in GeoJSON, it's usually pretty easy to work through loading them in as a JSON object.
The basics of a Polygon are:
var polygon = new google.maps.Polygon({
map: map,
paths: pointList
});
In this case, pointList
is your series of points that form the Polygon. After that, you can perform customization, add on click events, etc., but this is the bare minimum you need to load a polygon (assuming you already have a map object).
You can manually add points for very small testing purposes, but the GeoJSON route will lend better to development with a larger number of polygons.
You can find an example of loading GeoJSON polygons (a multipolygon in this case) into maps here:
http://www.alecbennett.com/projects/loadgeojson/
For zip code cartographic information, some is available here:
http://www.census.gov/geo/reference/zctas.html
And if you want someone that has already done some of the heavy lifting, check here:
https://github.com/ssoper/zip-code-boundaries
Upvotes: 1