1

我需要为谷歌地图的特定区域着色。我已经尝试过多边形叠加示例。. 这里使用的坐标如下:

var triangleCoords = [   
    new google.maps.LatLng(23.8099144,90.40607589999999,0),
    new google.maps.LatLng(24.8199144,86.40607589999999,0),
    new google.maps.LatLng(25.8299144,92.40607589999999,0),
    new google.maps.LatLng(23.8099144,90.40607589999999,0)
];

但我有如下格式的区域坐标:

89.90277900000007,22.36819100000007,0 89.90277900000007,22.36833399999999,0 89.90334400000013,22.36861000000009,0 89.903611,22.36889000000003,0 89.90416700000004,22.36917099999998,0 89.90499900000009,22.37001000000014,0 89.90499900000009,22.37111000000006,0 89.905281,22.37138800000008,0 89.905281,22.37833300000009,0 89.90333500000007,22.37833300000009,0 89.90166400000005,22.37527899999996,0 89.901391,22.3750010000001,089.90166400000005,22.36944400000003,0 89.90166400000005,22.36929200000004,0 89.90166400000005,22.36916600000013,0 89.90110800000001,22.36861000000009,0 89.90132199999998,22.36829099999999,0 89.90135199999997,22.368179,0 89.901391,22.36805600000009,0 89.90277900000007,22.36805600000009,0 89.90277900000007 ,22.36819100000007,0

现在我如何在代码中使用这个区域坐标值。该值来自数据库单个字段,并且很难将其一一合并到对象中,例如:

new google.maps.LatLng(89.90277900000007,22.36819100000007,0),
new google.maps.LatLng(89.90277900000007,22.36833399999999,0),
.
.
.
new google.maps.LatLng(89.90277900000007,22.36819100000007,0),

请给我一个合适的解决方案。

4

2 回答 2

1

使用此代码...

var res = "89.90277900000007,22.36819100000007,....,0 89.90277900000007,22.36819100000007,0";
resArray = res.split(" ");
var triangleCoords = [];

for(var i=0; i<resArray.length; i++){
    triangleCoords.push(new google.maps.LatLng(resArray[0]))
}
于 2013-06-28T06:46:07.430 回答
0

你可以试试这个方法。

从数据库中获取所有数据,然后按空格分割(使用您使用的任何服务器端语言或使用 javascript)。然后你会得到一个数组,尝试循环该数组并构建 latlng 对象。但是按空间分割并不是最好的方法,因为db中可能有没有空间的数据。

注意:新的 google.maps.LatLng(23.8099144,90.40607589999999,0),这里最后一个 arg 不是必需的。只有纬度和经度才能工作。

于 2013-06-27T12:21:30.180 回答