Javascript Geo Location

Javascript Geo location helps you find your user position(latitude and longitude) using javascript. First, it will try to locate user position via native html5 geolocation position and if that fails, fallback to GEO-IP api via freegeoip.net. This script requires jQuery.

Existing api has be known to be quirky, usually unstable and outputting inaccurate result for many developers. This library will minimize the pain and provide a better user-interaction and better fallback method so that you as a developer can get a more accurate reading on user position.

Demo:

Loading...

Usage

First, include geolocation.js in your before the closing of the HEAD tag

<script src="geolocation.js"></script>

After that, call getLocation(callback, timeout) with callback being your callback function and timeout being the number of miliseconds you want to wait before calling timeout.

For example:

    <script>
        //callback function
        function happy(x, y){
          alert('Latitude: ' + x + ' | Longitude: ' + y);
        }

        //call script
        getLocation(happy, 12000);
    </script>
    

Note