I'm trying to center the users current location on a map.
But I have a hard time figuring out why getCurrentPosition
is just skipped. When i debug it just skip the line.
What am i doing wrong?
initMap: function() {
var latLng;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
function(position) {
latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude)
}, function() {
latLng = new google.maps.LatLng(37.4, -122.1)
}, {
timeout: 10000
}
);
};
var mapOptions = {
center: latLng,
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
this.oMap = new google.maps.Map(this.getView().byId("map_canvas").getDomRef(), mapOptions);
this.geocoder = new google.maps.Geocoder();
this.directionsService = new google.maps.DirectionsService();
this.directionsDisplay = new google.maps.DirectionsRenderer({
draggable: true,
map: this.oMap,
suppressMarkers: true
});
this.createCurrentLocationMarker();
this.loadDataFromModel();
}