Hi,
I created the map using Google API, detected user’s current location using Cordova Geolocation Plugin and tested on both browser and mobile devices:
To install Cordova Geolocation Plugin, run the command cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
.controller('MapController', function($scope) {
$scope.drawMap = function() {
var myLatlng = new google.maps.LatLng(144.94623769999998, -37.8216962);
var mapOptions = {
center: myLatlng,
zoom: 13
};
$scope.map = new google.maps.Map(document.getElementById("map-div"),
mapOptions);
// Try HTML5 geolocation
if (navigator.geolocation) {
console.log("Device supports Geolocation");
navigator.geolocation.getCurrentPosition(function(position) {
console.log("Enter getCurrentPosition");
var pos = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
console.log(pos);
$scope.map.setCenter(pos);
var myLocation = new google.maps.Marker({
position: pos,
map: $scope.map,
content: 'Your location'
});
});
} else {
// Device doesn't support Geolocation
console.log("Device doesn't support Geolocation");
}
};
$scope.drawMap();
});