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', function myCoordinates($q) {

	var deferred = $q.defer();

	// Check your browser support HTML5 Geolocation API
	if (window.navigator && window.navigator.geolocation) {
		window.navigator.geolocation.getCurrentPosition(getCoordinates);
	} else {
		deferred.reject({msg: "Browser does not supports HTML5 geolocation"});
	}

	function getCoordinates(coordinates){
		var myCoordinates = {};
		myCoordinates.lat = coordinates.coords.latitude;
		myCoordinates.lng = coordinates.coords.longitude;
		deferred.resolve(myCoordinates);
	}

	return deferred.promise;

}])

Mikhail

I am Mikhail Evdokimov, a Hobbyist Self Taught Programmer