Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google maps API v3 municipal boundary [duplicate]

If one searches for a city on Google Maps, for example Berlin, the municipal boundaries of Berlin (gray dashed line with pink thick line inside) are shown.

Is it possible to make the same with Google Maps API?

like image 386
Petr Naumenko Avatar asked Mar 30 '12 08:03

Petr Naumenko


1 Answers

I think you want to put an outline on the map that defines an area, in your case the municipal area of Berlin.

I know in the United States there is Census data that has the longitude and latitudes of all of the counties that are available for download for free. I am not sure if Germany has something similar however a Google search for "long lat coordinates outline Berlin municipal" reveals lots of results.

So what do you do with the coordinates after you find them - Google Maps API allows you put Polygons on the map based on geo-coordinates.

I use the Google Encoded Polylines part of the Geometry library to store my polygons and then redisplay them when a specific state is being displayed.

Example

var map = new google.maps.Map(document.getElementById("googlemap"), myOptions);
var encodedpoints = "<encoded points string>";

var polyOptions = {
    "strokeColor": '#000000',
    "strokeOpacity": 1,
    "strokeWeight": 1,
    "fillColor": "#000000",
    "fillOpacity": 0.5
};
polyOptions.path = google.maps.geometry.encoding.decodePath(encodedpoints)
var mypolygon = new google.maps.Polygon(polyOptions);
mypolygon.setMap(map);

This example will put a polygon on the map that has a black line border and 50% opacity black fill. You can change the options to whatever you want.

like image 164
Geek Num 88 Avatar answered Oct 16 '22 03:10

Geek Num 88