How Can I Draw a Polygon on Google Maps Using Postcodes Instead of Coordinates?
Asked by
ascender7pt
I'm trying to create a polygon using the Google Maps API, but instead of providing specific coordinates, I want to use UK postcodes like TW1, TW2, TW3, TW4, and TW5. I've noticed that when entering a postcode directly in Google Maps, a polygon is automatically displayed, like with TW1. Is there a way to do this programmatically using the API? Can I input all the postcodes at once or do I need to handle them one by one?
Answers
In the US, the Census Bureau offers KML files based on postal divisions. You might want to check if similar resources exist for the UK from local postal services. This could help you create the polygons you need more easily.
Reply to this answer
Try looking online for the latitude and longitude boundary data for UK postcode outcodes. Once you have that, you can manually create the polygons using the Google Maps API. I did something similar a while back and stored the polygon data in SQL for easy querying.
Reply to this answer
Unfortunately, the Google Maps API doesn't let you draw polygons directly from postcodes. Instead, you would need to convert each postcode into the corresponding polygon coordinates using a service like MapIt. After that, use those coordinates with the Maps API. Just a heads-up, there's no way to input multiple postcodes at onceโyou'll have to handle each one separately.
Reply to this answer
Google Maps does indeed have boundaries for postcodes, but you need to provide the data for your coverage maps because the API isn't designed for this use case directly. You might consider generating KML files for your polygonic needs to load into Google Maps.
fizzletop: Exactly! While you can type a postcode and see the area in Maps, the API requires that you provide the data. KML files will definitely be useful for constructing what you need.
Reply to this answer
Add your answer
Answers are reviewed before publication.
!pause for effect: Thatโs right! You can find KML files that outline specific areas, including postal codes. Itโs worth searching around for government resources that might have this data structured for you.