开发者

GoogleMaps API draw polygon over a complete town

开发者 https://www.devze.com 2022-12-25 21:41 出处:网络
I\'m wondering if it\'s actually possible to draw a polygon over a complete town with the GoogleMaps API V3 or the V2?

I'm wondering if it's actually possible to draw a polygon over a complete town with the GoogleMaps API V3 or the V2?

If so could you please 开发者_如何转开发give an example on how to do it (choose your favorite town :)).

I've some difficulties understanding this API.

Thanks.


If you want to outline the boundary of a town, you're going to need some additional data that tells you where to draw. Shape files are good for this sort of thing, and it is generally easy to find free or low-cost files that provide boundaries of cities, states, counties, countries, etc. Just do a google search for "[CityName] shape files" or something like that.

Once you have a good shape file, you can query it for all of the points in the boundary. You would then call the method to draw a polygon with those points in the maps api.


I don't think it is possible to draw a polygon around a town boundary automatically; you need to know the coordinates of the corners, and then you draw a polygon connecting those points (so the information about where the town boundaries are doesn't come from Google Maps, but from your application).

Then, you can create a polygon like so:

  var polygon = new GPolygon([
    new GLatLng(lat, lon - lonOffset),
    new GLatLng(lat + latOffset, lon),
    new GLatLng(lat, lon + lonOffset),
    new GLatLng(lat - latOffset, lon),
    new GLatLng(lat, lon - lonOffset)
  ], "#f33f00", 5, 1, "#ff0000", 0.2);
  map.addOverlay(polygon);

(Example code taken from the API docs.)


Here's a very interesting (free) open project for Administrative Geographical Data : http://www.openstreetmap.org

0

精彩评论

暂无评论...
验证码 换一张
取 消