我使用谷歌地图绘制形状 但是当我试图从数据库获取lat和lng并将其分配给地图时,我会收到错误
从数据库中获取格式数据
for (var s = 0; s < array_points.length; s++) {
var shapeCoordinates = array_points[s];
var shap = Array();
for (var sh = 0; sh < shapeCoordinates.length; sh++) {
shap.push({lat: shapeCoordinates[sh]['lat'], lng: shapeCoordinates[sh]['lng']});
var drawingManager = new google.maps.Polygon({
paths: shap,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35
});
}
}
我收到以下错误
Uncaught InvalidValueError: at index 0: not a LatLng or LatLngLiteral: in property lat: not a number
array_points有3个形状
shapeCoordinates具有形状坐标
答案 0 :(得分:1)
请将此变量转换为整数,它将解决您的问题。
parseFloat(shapeCoordinates[sh]['lat'])
答案 1 :(得分:0)
请尝试此
for (var s = 0; s < array_points.length; s++) {
var shapeCoordinates = array_points[s];
var shap = [];
for (var sh = 0; sh < shapeCoordinates.length; sh++) {
shap.push({lat: shapeCoordinates[sh]['lat'], lng: shapeCoordinates[sh]['lng']});
}
var drawingManager = new google.maps.Polygon({
paths: shap,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35
});
drawingManager.setMap(map);
}