center map position
I'm attempting to center the map on the current position and Im getting
undefined is not a function related to setCenter
the code is below
$scope.map = { center: { latitude: 45, longitude: -73 }, zoom: 8 }; $scope.options = {scrollwheel: false}; $scope.showWeather = true; $scope.showTraffic = true;
$scope.positions = [{
lat: 43.07493,
lng: -89.381388
}];
$scope.$on('mapInitialized', function(event, map) {
$scope.map = map;
});
$scope.centerOnMe = function() {
if(!$scope.map) {
return;
}
$scope.loading = $ionicLoading.show({
content: 'Getting current location.',
showBackdrop: false
});
navigator.geolocation.getCurrentPosition(function(pos) {
$scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
$scope.loading.hide();
}, function(error) {
alert('Unable to get location: ' + error.message);
});
Any thoughts?
You can just set the latitude and longitude properties of the center property of your map
$scope.map.center = {
latitude:pos.coords.latitude,
longitude: pos.coords.longitude
};
The map center object has been updated successfully but the map isn't updated to the new location
Any help?
Same as iMomen here.
plnkr?
I have the same problem. Any solution on this? Can you run setCenter at all or do I have to instantiate a google map instance in my controller the old fashioned way var map = new google.map etc....
+1. updating the center object does not recenter the map. Zoom works for me this way though.
Please use githubs thumbs up, no need for +1's anymore
How are you guys updating the center object? This is why we need an example via plnkr!
Also the code for how the centering is updated is here . Walk through the debugger there to get an idea on what is causing to bail or not.
Hey @nmccready Please have a look at the following plunkr http://plnkr.co/edit/M6wFwY8UW9ZCo9ABPzPx?p=preview
In the above try to move the map somewhere and click Recenter. The map is expected to center around the placed marker but it doesn't. But if you change the angular-google-maps version to 2.3.2 it works.
Further investigation
v2.1.5 with lodash 3.40 - works v2.1.6 - v2.3.1 - Not working v2.3.2 - working v2.3.3 & v2.3.4 - Not working
Hope this is helpful!
In all cases zoom worked as expected
@youfacepalm thanks!
For anyone else landing here with the same problem as @youfacepalm, you have to replace the center object itself, it is not sufficient to change it's latitude/longitude properties.