admin管理员组文章数量:1331926
I created a map with the Google Maps API (Javascript) as follows:
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
});
I was then trying to use the bound.contain function to check whether various LatLng positions are contained within the map bounds or not:
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)
After some debugging, it seems that the currentLocation Object doesn't have the right format to be processed with the method "contains". Please note that I'm quite new to javascript and the Google Maps api.
Thanks in advance for your help.
I created a map with the Google Maps API (Javascript) as follows:
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
});
I was then trying to use the bound.contain function to check whether various LatLng positions are contained within the map bounds or not:
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)
After some debugging, it seems that the currentLocation Object doesn't have the right format to be processed with the method "contains". Please note that I'm quite new to javascript and the Google Maps api.
Thanks in advance for your help.
Share Improve this question asked Feb 21, 2016 at 22:18 petepete 211 silver badge3 bronze badges1 Answer
Reset to default 8LatLngBounds.contains
currently requires a LatLng
as argument, a LatLngBoundsLiteral
will not be accepted.
Use
var currentLocation = new google.maps.LatLng(47.3663615,8.5388539);
本文标签: Google Maps Javascript APIboundscontains methodStack Overflow
版权声明:本文标题:Google Maps Javascript API - bounds.contains method - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742257675a2441927.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论