Google maps 使用此格式在谷歌地图中构建多边形
我试图在谷歌地图中显示多边形。我有一个.xlsx文件,其中有一列名为“polygon”,其中的多边形坐标格式很奇怪 例如:Google maps 使用此格式在谷歌地图中构建多边形,google-maps,polygon,Google Maps,Polygon,我试图在谷歌地图中显示多边形。我有一个.xlsx文件,其中有一列名为“polygon”,其中的多边形坐标格式很奇怪 例如:,[-68.07908, -38.94347], [-68.08127, -38.94434], [-68.08457, -38.94739], [-68.1084, -38.9478], [-68.10842, -38.95442], [-68.0914, -38.9549], [-68.09136, -38.95559], [-68.09123, -38.95594]],
,[-68.07908, -38.94347], [-68.08127, -38.94434], [-68.08457, -38.94739], [-68.1084, -38.9478], [-68.10842, -38.95442], [-68.0914, -38.9549], [-68.09136, -38.95559], [-68.09123, -38.95594]], [[-68.11045, -38.95312]], [[-68.09643, -38.96523], [-68.0967, -38.95809], [-68.09688, -38.95342], [-68.07472, -38.95842], [-68.04073, -38.95897], [-68.03989, -38.95899], [-68.03897, -38.95901], [-68.0391, -38.96296], [-68.04457, -38.96303], [-68.04461, -38.96304], [-68.04488, -38.97065], [-68.04485, -38.97065], [-68.04489, -38.97132], [-68.05176, -38.97112], [-68.05704, -38.97265], [-68.05725, -38.97858], [-68.06837, -38.97866], [-68.06886, -38.97315], [-68.06901, -38.96554], [-68.07631,-38.96542]]
是否可以使用此数据结构构建多边形,或者它的格式不正确?您的数据是类似GeoJSON的坐标格式 要将其转换为Google Maps多边形,请执行以下操作:
// go through the outer array (of polygons)
for (var i = 0; i < coords.length; i++) {
// array for the LatLng coordinates
var polygonCoords = [];
// go through each coordinate in the array.
// GeoJSON is [longitude,latitude]
for (var j = 0; j < coords[i].length; j++) {
var pt = new google.maps.LatLng(coords[i][j][1], coords[i][j][0])
polygonCoords.push(pt);
}
// Construct the polygon.
var polygon = new google.maps.Polygon({
paths: polygonCoords,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35,
map: map
});
}
}