Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
ngGeolocation
Advanced tools
###### AngularJS support for [HTML5 Geolocation API](http://www.w3.org/TR/geolocation-API/)
ngGeolocation provides AngularJS support for the HTML5 Geolocation API. It aims to provide a quick and easy way to consume geolocation information made available by modern browsers and HTML5 in AngularJS apps wtihout having to write custom SDK wrapping code. Everything exposed by the $geolocation
service lives within the digest cycle, so there is no need to use $scope.$apply()
in your controllers when consuming the service. ngGeolocation goes one step further than wrapping the HTML5 API calls and provides a property that can be $watch
ed by your controllers which will always contain the latest position data available through the browser.
The bower package name is ngGeolocation
.
bower.json
{
"dependencies": {
"ngGeolocation": ">=0.0.2"
}
}
bower install ngGeolocation
Include the installed scripts in your html...
<script src="bower_components/ngGeolocation.min.js"/>
Download the minified or unminified source.
Include the scripts in your html...
<script src="lib/ngGeolocation.min.js"/>
Make sure your app depends on the ngGeolocation
module. Geolocation methods are available through the $geolocation
service.
angular
.module('myApp', ['ngGeolocation'])
.controller('geolocCtrl', ['$geolocation', '$scope', function($geolocation, $scope) {
$geolocation.getCurrentPosition({
timeout: 60000
}).then(function(position) {
$scope.myPosition = position;
});
}]);
The $geolocation
service can expose a property location
whose value reflects the current position. To enable this feature a watch must be created using watchPosition
. This method takes a PositionOptions
object in the same manner as getCurrentPosition
. There is no return value.
While this watch is active the value of the property location
is periodically updated with the latest geolocation result. If an error has occurred the code and message are available via $geolocation.position.error
.
The current watch can be cancelled using clearWatch
.
angular
.module('myApp', ['ngGeolocation'])
.controller('geolocCtrl', ['$geolocation', '$scope', function($geolocation, $scope) {
$geolocation.watchPosition({
timeout: 60000,
maximumAge: 250,
enableHighAccuracy: true
});
$scope.myCoords = $geolocation.position.coords; // this is regularly updated
$scope.myError = $geolocation.position.error; // this becomes truthy, and has 'code' and 'message' if an error occurs
}]);
angular-google-maps
Here's an example from @markmcdonald51 for using ngGeolocation with angular-google-maps...
angular
.module('MyApp', ['ngGeolocation', 'google-maps'])
.controller('geolocCtrl', ['$geolocation', '$scope', function($geolocation, $scope) {
$geolocation.watchPosition({
timeout: 60000,
maximumAge: 250,
enableHighAccuracy: true
})
$scope.$watch('myPosition.coords', function (newValue, oldValue) {
$scope.map = {
center: {
latitude: newValue.latitude,
longitude: newValue.longitude
},
zoom: 16
};
}, true);
});
This project uses Grunt for tooling. The toolbelt dependencies are managed by NPM and the production code dependencies are managed by Bower. Fork the code and clone it into your workspace, then...
npm install
bower install --dev
Tests can be run manually with grunt test
or automatically on changes with grunt
.
NB The minified file is generated by grunt build
- all console logging is stripped out of the minified file using grunt-strip
.
If you wish to contribute, please raise an issue or submit a pull request which includes:
ngGeolocation.min.js
)FAQs
###### AngularJS support for [HTML5 Geolocation API](http://www.w3.org/TR/geolocation-API/)
The npm package ngGeolocation receives a total of 333 weekly downloads. As such, ngGeolocation popularity was classified as not popular.
We found that ngGeolocation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.