Giter Club home page Giter Club logo

geolocator's Introduction



CDNJS bower npm release Code Climate dependencies license maintained

© 2017, Onur Yıldırım (@onury) MIT License. Please see the Disclaimer and License.

Geolocator.js is a utility for getting geo-location information, geocoding, address look-ups, distance & durations, timezone information and more...

Features

  • HTML5 geolocation (by user permission) with improved accuracy.
  • Location by IP
  • Reverse Geocoding (address lookup)
  • Full address information (street, town, neighborhood, region, country, country code, postal code, etc...)
  • Fallback mechanism (from HTML5-geolocation to Geo-IP lookup)
  • Watch geographic position
  • Locate by mobile information
  • Get timezone information
  • Get distance matrix and duration information
  • Calculate distance between two geographic points
  • Various geographic conversion utilities
  • Get client IP
  • Fetched location includes country flag image (SVG) URL
  • Language support (depends on the service provider)
  • Supports Google Loader (loads Google APIs dynamically)
  • Dynamically create Google Maps, on demand (with marker, info window, auto-adjusted zoom)
  • Get static Google Map (image) URL for a location
  • Non-blocking script loading (external sources are loaded on the fly without interrupting page load)
  • No library/framework dependencies (such as jQuery, etc...)
  • Universal module (CommonJS/AMD..)
  • Small file size (9KB minified, gzipped)
  • Browser Support: IE 9+, Chrome, Safari, Firefox, Opera...

See a Live Demo.

Get Geolocator.js

Link or download via CDNJS.

Download full source code from GitHub releases.

Install via Bower:

bower install geolocator

Install via NPM:

npm install geolocator

Usage:

Example below, will attempt to get user's geo-location via HTML5 Geolocation and if user rejects, it will fallback to IP based geo-location.

Inside the <head> of your HTML:

<script type="text/javascript" src="geolocator.min.js"></script>
<script type="text/javascript">

    geolocator.config({
        language: "en",
        google: {
            version: "3",
            key: "YOUR-GOOGLE-API-KEY"
        }
    });

    window.onload = function () {
        var options = {
            enableHighAccuracy: true,
            timeout: 5000,
            maximumWait: 10000,     // max wait time for desired accuracy
            maximumAge: 0,          // disable cache
            desiredAccuracy: 30,    // meters
            fallbackToIP: true,     // fallback to IP if Geolocation fails or rejected
            addressLookup: true,    // requires Google API key if true
            timezone: true,         // requires Google API key if true
            map: "map-canvas",      // interactive map element id (or options object)
            staticMap: true         // map image URL (boolean or options object)
        };
        geolocator.locate(options, function (err, location) {
            if (err) return console.log(err);
            console.log(location);
        });
    };

</script>

If you've enabled map option; include the following, inside the <body> of your HTML:

<div id="map-canvas" style="width:600px;height:400px"></div>

Read API documentation for lots of other features and examples.

Important Notes

  • Since Geolocation API is an HTML5 feature, make sure your doctype is HTML5 (e.g. <!DOCTYPE html>).
  • Make sure you're calling Geolocation APIs (such as geolocator.locate() and geolocator.watch()) from a secure origin (i.e. an HTTPS page). In Chrome 50, Geolocation API is removed from unsecured origins. Other browsers are expected to follow.
  • Although some calls might work without a key, it is generally required by most Google APIs (such as Time Zone API). To get a free (or premium) key, click here. After getting a key, you can enable multiple APIs for it. Make sure you enable all the APIs supported by Geolocator. (If you don't have a key, you can still use Geolocator like the previous versions, but with limited features.)
  • Geolocator now supports a single Geo-IP provider, FreeGeoIP. You can use geolcoator.setGeoIPSource() method to set a different Geo-IP source.
  • On Firefox, callback is not fired for Geolocation, if user clicks "Not Now" instead of "Never". This is now fixed in Firefox version 53 with the new permission prompt redesign. (See bugzilla 675533.)

Under the Hood

Geolocator v2 is written in ES2015 (ES6), compiled with Babel, bundled with Webpack and documented with Docma.

Change Log

See version changes here.

License

MIT. See the Disclaimer and License.

geolocator's People

Contributors

onury avatar iurisilvio avatar peterdavehello avatar

Watchers

 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.