I am Mikhail Evdokimov, a Hobbyist Self Taught Programmer
AngularJS Geolocation Application. Part 2 - HTML5 Geolocation API
January
8th,
2016
This article is an addition to my previous article AngularJS Geolocation Application Step by Step
In this article I will tell how to use HTML5 Geolocation API for get geolocation data. Latitude and Longitude.
Replace code in js/location.js with
app.factory('myCoordinates',['$q',functionmyCoordinates($q){vardeferred=$q.defer();// Check your browser support HTML5 Geolocation APIif(window.navigator&&window.navigator.geolocation){window.navigator.geolocation.getCurrentPosition(getCoordinates);}else{deferred.reject({msg:"Browser does not supports HTML5 geolocation"});}functiongetCoordinates(coordinates){varmyCoordinates={};myCoordinates.lat=coordinates.coords.latitude;myCoordinates.lng=coordinates.coords.longitude;deferred.resolve(myCoordinates);}returndeferred.promise;}])