Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 222
Tahir Avatar asked Jun 17 '11 16:06

Tahir


People also ask

How do I highlight country borders in Google Maps?

To achieve this, you will basically need to look for the coordinates of the state or country on GADM. Once you have them, draw a shape on the Google Maps with the Polygon object providing an array with all the coordinates that play basically as borders of the place that you want to highlight.

Can you highlight an area on Google Maps?

You can trace a path or highlight an area on your map by drawing lines and shapes.


3 Answers

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.

like image 154
Tahir Avatar answered Sep 21 '22 21:09

Tahir


You can also try Google Geo Charts:

http://code.google.com/apis/chart/interactive/docs/gallery/geochart.html

like image 10
Renato Avatar answered Sep 25 '22 21:09

Renato


Google Maps API doesn't allow you to retrieve city borders. There are a couple other places from which you can get the coordinates, though:

Flickr API

There is a Flickr API based on photos that people tag, but it's only as accurate as the people who tag photos: so it's good enough for bootstrapping but probably not for production: http://karya-blog.blogspot.com/2012/12/fetching-city-polygons-with-flickr-api.html

Natural Earth Data

An accurate alternative is www.naturalearthdata.com. To get that data from there you just need to make two requests: one with the city name and one with their ID to get the parameters:

unlock.edina.ac.uk/ws/search?name=berlin&gazetteer=naturalearth&format=json

and then

unlock.edina.ac.uk/ws/footprintLookup?format=json&identifier=14126951

and you're set :)

Mapzen

If it's possible for you to pre-fetch the data, go for Mapzen, they have a full and pretty accurate database: https://mapzen.com/data/borders/

like image 5
Wojtek Szkutnik Avatar answered Sep 21 '22 21:09

Wojtek Szkutnik