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);