如何从选定的地图范围中获取WKT或GeoJson中的边界

时间:2015-05-21 18:40:41

标签: google-maps

尝试在谷歌地图选定范围区域中获取边界,但听起来它只包含这样的值:

enter image description here

不确定如何将其正确格式化为POLYGON。请帮忙,无法在google api v3

中找到相关文档

2 个答案:

答案 0 :(得分:1)

我希望这很有用

你可以用这种方式得到界限(假设地图是地图)

    aNord   =   map.getBounds().getNorthEast().lat();   
    aEst    =   map.getBounds().getNorthEast().lng();
    aSud    =   map.getBounds().getSouthWest().lat();   
    aOvest  =   map.getBounds().getSouthWest().lng();   

对于WKT转换,您只需要反转lat,lng WKT使用coord(x,y)google use coord(y,x)

答案 1 :(得分:1)

完整的功能

function getWKTOfGoogleMap() {
    var neLat = map.getBounds().getNorthEast().lat();
    var neLng = map.getBounds().getNorthEast().lng();
    var swLat = map.getBounds().getSouthWest().lat();
    var swLng = map.getBounds().getSouthWest().lng();

    return "POLYGON((" +
            swLng + " " + swLat + "," +
            swLng + " " + neLat + "," +
            neLng + " " + neLat + "," +
            neLng + " " + swLat + "," +
            swLng + " " + swLat +
            "))";
}