Highlighting borders of state and cities of US in Google Map API 3

Tahir Akram picture Tahir Akram · Jun 17, 2011 · Viewed 46.9k times · Source

I have a scenario where I have to highlight borders and shade a state or city after geocoding it (when I got the lang and lat).

How can I do this, do I need to have a complete information of a city to surround it with polylines? Or is there a way that map API can do this for me.

Answer

Tahir Akram picture Tahir Akram · Jul 2, 2011

True. Google does not provide this feature. So what we can do... we can have the lat/long of the borders of the state. And we have to draw polygons ourselves.

I used this JS object. And changed it to Google map object (google.maps.LatLng).

For example:

var statesobj = {"AK": [new google.maps.LatLng(70.0187, -141.0205),
new google.maps.LatLng(70.1292, -141.7291),
new google.maps.LatLng(70.4515, -144.8163)]}

So, it's easy now. Loop on these lat/longs. And you can draw the polygons on every state of US.

So this is the solution I came up. If you guys know some better idea to do it. Please share.