Giter Site home page Giter Site logo

mattisg / locate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cbeloch/locate

1.0 3.0 0.0 171 KB

A MooTools interface over W3C's Geolocation API, allowing for MooTools-style events listening and masking cross-browser API differences.

JavaScript 100.00%

locate's Introduction

Locate

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.

Screenshot

How to use

Include the Locate.js in your project.

Use Code like this:

#JS
var location = new Locate({
	onLocate: function(position){
		alert('latitude: ' + position.latitude, '; longitude: ' + position.longitude + '; accuracy: ' + position.accuracy);
	}
});

See below for more details about position fields.

Want to frequently get the position (watch your visitor move)?

#JS
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!

#JS
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:

#JS
var location = new Locate({
	loiType: 'watch',
	onLocate: function(position){
		$("distance").set('html', this.distanceTo(37.3316591, -122.0301778));
	}
});

Position data

The position data given with the event 'locate' looks like this:

  • position.latitude
  • position.longitude
  • position.altitude
    • null if not supported, meters above the WGS84 ellipsoid
  • position.accuracy
    • specified in meters
  • position.altitudeAccuracy
    • specified in meters
  • position.heading
    • null if not supported, specified in degrees counting clockwise to true north
  • position.cardinalDirection
    • not part of the official W3C specifications!
    • can be null
    • returns the heading direction as string (cardinal direction): "N", "NE", "E" etc.
  • position.speed
    • null if not supported, specified in meters per second

If you use Locate.Extras, you can also use

  • position.address
    • returns your current address based on GMaps
    • If you want to use this feature, use this.address() within the onLocate function
    • You have to use the watcher method atm, working on a fix

ToDo

  • make position.address work without watcher method
  • find an alternative to GMaps

locate's People

Contributors

cbeloch avatar mattisg avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.