【发布时间】:2016-08-25 21:31:48
【问题描述】:
我正在使用 MEAN Stack 和 Google Maps Api 构建应用程序,但在绘制 多边形 时遇到了一点问题> 和 LineStrings。
我有一组几何图形(点、多边形和线串),每次找到其中一个时,我都需要将其正确添加到地图中。
在渲染标记方面我没有问题,但在多边形和线串方面我有问题。
这是我的代码,其中包含初始化地图的逻辑。
// Initializes the map
function initialize(latitude, longitude, filter) {
// If map has not been created...
if (!map) {
// Create a new map and place in the index.html page
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: new google.maps.LatLng(vm.selectedLat, vm.selectedLong)
});
}
// Loop through each location in the array and place a geometry
locations.forEach(function (n) {
if(n.type === 'LineString'){
console.log('LineString '+JSON.stringify(n.coords));
var linestring = new google.maps.Polyline({
position: n.coords,
map: map,
geodesic: true,
strokeColor: '#0404B4',
strokeOpacity: 1.0,
strokeWeight: 2
});
// For each linestring created, add a listener
google.maps.event.addListener(linestring, 'click', function () {
// When clicked, open the selected linestring's message
n.message.open(map, linestring);
});
linestring.setMap(map);
}
if(n.type === 'Polygon'){
console.log('Polygon '+JSON.stringify(n.coords));
var polygon = new google.maps.Polygon({
path: n.coords,
geodesic: true,
strokeColor: '#0404B4',
strokeOpacity: 0.8,
strokeWeight: 3,
fillColor: '#0404B4',
fillOpacity: 0.35
});
// For each polygon created, add a listener
google.maps.event.addListener(polygon, 'click', function () {
// When clicked, open the selected polygon's message
n.message.open(map, polygon);
});
polygon.setMap(map);
}
});
};
这里是坐标的两个console.log()的截图
正如您从屏幕截图中看到的那样,我也得到了
InvalidValueError: at index 0: not a LatLng or LatLngLiteral: in property lat: not a number
我试图找到解决方案,但没有成功。
为什么我不能绘制这些几何图形?如何解决 InvalidValueError?
提前致谢。
【问题讨论】:
标签: javascript angularjs google-maps google-maps-api-3