How Can I Draw a Polygon on Google Maps Using Postcodes Instead of Coordinates?

August 1, 2025 4 answers
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

_castlingQ2
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.

!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.

Reply to this answer
pinch of thyme
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
!rotate the crops
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
Lentil
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.

Related Discussions