在Google地图上创建一个网格并获取坐标

时间:2016-07-13 00:40:15

标签: javascript google-maps

我从这个链接http://www.geocodezip.com/v3_MW_example_click2addMarkerSquareB.html

获取了这段代码
var map = null;
var infowindow = new google.maps.InfoWindow();
var encodedPolyline = "";

var myOptions = {
    zoom: 20,
    center: new google.maps.LatLng(-37.815334, 144.961332),
    mapTypeControl: false,
    navigationControl: false,
    mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(
    document.getElementById("map"),
    myOptions
);

var point = new google.maps.LatLng(-37.815334, 144.961332);
var radius = 10/2;

var square = new google.maps.Rectangle({bounds:(new google.maps.Circle({center: point, radius: radius}).getBounds()),
    strokeColor: "#ff0000",
    strokeWeight: 1,
    strokeOpacity: 1.0,
    fillOpacity: 0.0
});
square.setMap(map);
var marker = new google.maps.Marker({ position: map.getCenter(), map: map});

这会在中心点周围创建一个正方形。我现在需要解决的是如何在主广场周围创建许多其他正方形,右边和顶边对齐创建一个网格。网格应该只从原始方块向右上方移动。

我试过了:

for(var i = 0; i < 10; i++)
{
    var point = new google.maps.LatLng(square.getBounds().getNorthEast().lat(), square.getBounds().getNorthEast().lng());

    var square = new google.maps.Rectangle({bounds:(new google.maps.Circle({center: point, radius: radius}).getBounds()),
        strokeColor: "#ff0000",
        strokeWeight: 1,
        strokeOpacity: 1.0,
        fillOpacity: 0.0
    });
    square.setMap(map);
}

但是这会从最后一个NW点创建新的方形中心。如果可能,我想指定网格应该有多大,即100 x 100

由于

0 个答案:

没有答案