-1

I know what i can get JSON LatLon (and other) data indicate my address in the URL

app.factory('myCoordinates', function myCoordinates($q, $http) {

    var deferred = $q.defer();

    $http.get('http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false&region=$region')
            .success(function(coordinates) {
                var myCoordinates = {};
                myCoordinates.lat = coordinates.results[0].geometry.location.lat;
                myCoordinates.lng = coordinates.results[0].geometry.location.lng;
                myCoordinates.zoom = 14;
                deferred.resolve(myCoordinates);
        })

    return deferred.promise;

});

http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false&region=$region

But how can i get latitude and longitude coordinates of my current location without input my address in URL (automatically) ?

Mikhail
  • 11,067
  • 7
  • 28
  • 53

1 Answers1

3

How about using html5 navigator.geolocation.getCurrentPosition to get the latitude and longitude?

Example:

navigator.geolocation.getCurrentPosition(function(pos){
  console.log(pos)
});
Chanthu
  • 1,794
  • 1
  • 15
  • 22
  • Yes, it's a really good way. But what do you think more accurately shows the location, Google API or HTML5 Geolocation? I would like as accurately as possible to show the user's location in the application – Mikhail Jan 03 '16 at 06:48
  • This is the link to the official documentation and looks like they're using navigator as well. soo.. https://developers.google.com/maps/articles/geolocation – Chanthu Jan 03 '16 at 06:50
  • Related: http://stackoverflow.com/questions/13780583/get-current-location-on-google-map – Chanthu Jan 03 '16 at 06:55