我有我认为非常简单的代码。我画了一个多边形,一个标记,然后如果我硬编码的点在多边形内,就会发出警报。然而,当我运行它时,我Uncaught TypeError: Cannot call method 'lng' of undefined
在控制台中得到一个“”错误。
我的代码如下:
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(38.990842,-76.93625),
zoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
var box = [new google.maps.LatLng(38.9913160,-76.937079),
new google.maps.LatLng(38.991333,-76.936119),
new google.maps.LatLng(38.990287, -76.936108),
new google.maps.LatLng(38.990278,-76.937057),
new google.maps.LatLng(38.990495,-76.937052),
new google.maps.LatLng(38.990499,-76.936424),
new google.maps.LatLng(38.991091,-76.93643),
new google.maps.LatLng(38.991104,-76.937079)
];
var mPoint = [new google.maps.LatLng(38.991300,-76.936165)];
var marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(38.991300,-76.936165),
//position: new google.maps.LatLng(mPoint),
draggable: true
});
var AVpoly = new google.maps.Polygon({path:box,
strokeColor:"#0000FF",
strokeOpacity:0.8,
strokeWeight:2,
fillColor:"#0000FF",
fillOpacity:0.4});
AVpoly.setMap(map);
marker.setMap(map);
if(google.maps.geometry.poly.containsLocation(google.maps.LatLng(38.990842,-76.93625), box) == true) {
alert("yes");
}
}
我看不出这有什么问题,也看不出为什么不触发警报。我什至把它改成了假,因为我的几何形状是错误的......