With Locate you can easily access a visitors geolocation if his browser supports this feature. The basic geolocation API is a bit complicated (check W3C Geolocation API Specification for more info) in my oppinion. I hope I can make it easier to handle with all the data by using this little MooTools class. There are so many possibilities by using location based information in your webapp.
Now you can build your own Google Buzz clone with MooTools power. Let me know on how you used it in your webapplication.
Include the Locate.js in your project.
Use Code like this:
var location = new Locate({ onLocate: function(position){ // Do stuff with the position data } });
Want to frequently get the position (watch your visitor move)?
var location = new Locate({ loiType: 'watch', onLocate: function(position){ // Do stuff with the position data } });
Don't want to locate directly on initializing the Class? No problem!
var location = new Locate({ loi: false }); // start locating later in your code using this line // you can also use location.watcher(); location.locate();
Want to get the distance from the current position to another? No problem, the function distanceTo() returns the distance in km:
var location = new Locate({ loiType: 'watch', onLocate: function(position){ $("distance").set('html', this.distanceTo(37.3316591,-122.0301778)); } });
The position data given with the event 'locate' looks like this:
If you use Locate.Extras, you can also use
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus