pet*_*ete 1 javascript google-maps-api-3
我使用Google Maps API(Javascript)创建了地图,如下所示:
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
});
Run Code Online (Sandbox Code Playgroud)
然后,我尝试使用bound.contain函数检查地图范围内是否包含各种LatLng位置:
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)
Run Code Online (Sandbox Code Playgroud)
经过一些调试后,似乎currentLocation对象的格式不正确,无法使用方法“ contains”处理。请注意,我对javascript和Google Maps api还是很陌生。
在此先感谢您的帮助。
LatLngBounds.contains当前需要一个LatLngas参数,a LatLngBoundsLiteral将不被接受。
使用
var currentLocation = new google.maps.LatLng(47.3663615,8.5388539);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3206 次 |
| 最近记录: |