navigator.geolocation reverse geo get your location

navigator.geolocation reverse geo get your location

by Andrew Pougher

HTML

<div id="result"></div>

CSS

#map_canvas {
    height:300px;
    width:100%;
}

JavaScript

$(function() {

        var Geo={};

        if (navigator.geolocation) {
           navigator.geolocation.getCurrentPosition(success, error);
        }

        //Get the latitude and the longitude;
        function success(position) {
            Geo.lat = position.coords.latitude;
            Geo.lng = position.coords.longitude;
            populateHeader(Geo.lat, Geo.lng);
        }

        function error(){
            alert("Geocoder failed");
        }

        function populateHeader(lat, lng){
            $('#result').append(lat + ",");
            $('#result').append(lng);
        }

    });