1
我创建了谷歌地图API(JavaScript)的地图如下:谷歌地图API的Javascript - bounds.contains方法
var currentLocation = {lat: 47.3663615, lng: 8.5388539};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: zoomLevel,
center: currentLocation,
mapTypeId: google.maps.MapTypeId.TERRAIN
});
然后我试图使用bound.contain函数来检查是否不同经纬度位置被包含在地图范围或不在:
var center = map.getCenter(); // works fine
var bounds = map.getBounds(); // works fine
var x = bounds.contains(center); // works fine, delivers true
var a = bounds.contains(currentLocation); throws an error (Uncaught TypeError: a.lat is not a function)
一些调试后,似乎currentLocation对象不具备与方法处理正确的格式“载”。请注意,我对JavaScript和Google Maps API相当陌生。
在此先感谢您的帮助。
修正的建议。现在工作得很好。非常感谢您的及时答复和提示。 – pete