3
votes

How do I retrieve my current location in javascript using the angularjs-google-maps api by allenhwkim?

Currently I am able to access my current location through the html code

<marker animation="DROP" position="current-location"></marker>

however I wish to implement a current location button which will let me center the map to my current location whenever I am away from my current location itself.

html:

<input type="submit" Value="currentLocation" ng-click ="currentLocation()"/>

js:

$scope.currentLocation = function(){
        //how do i get current location?
};

thank you!

1

1 Answers

8
votes
var options = {
                enableHighAccuracy: true
            };

navigator.geolocation.getCurrentPosition(function(pos) {
                $scope.position = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
                console.log(JSON.stringify($scope.position));                  
            }, 
            function(error) {                    
                alert('Unable to get location: ' + error.message);
            }, options);