Click here to Skip to main content
15,850,103 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
HTML
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
<p>Click the button to get your coordinates.</p>

<button onclick="getLocation()">Try It</button>

<p id="demo"></p>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
    var x = document.getElementById("demo");
    var Latitudevar;
    var Longitudevar;
    function getLocation() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(showPosition);
        } else {
            x.innerHTML = "Geolocation is not supported by this browser.";
        }
    }

    function showPosition(position) {

        x.innerHTML = "Latitude: " + position.coords.latitude +
    "<br>Longitude: " + position.coords.longitude;


        Latitudevar = position.coords.latitude;
        Longitudevar = position.coords.longitude;

        GetAddress();
    }

    function GetAddress() {


        var lat = Latitudevar;
        var lng = Longitudevar;
        var latlng = new google.maps.LatLng(lat, lng);
        var geocoder = geocoder = new google.maps.Geocoder();
        geocoder.geocode({ 'latLng': latlng }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                if (results[1]) {
                   // alert("Location: " + results[1].formatted_address);
                    x.innerHTML = "Area: " + results[1].formatted_address;
                }

            }
        });

    }
</script>

</body>
</html>
Posted
Updated 22-Jun-15 4:41am
v4
Comments
Thanks7872 22-Jun-15 9:23am    
Why you are posting all your explanation as a solution? Look at bottom of the question, there is a link "Improve question", use it.
hariprashanth11 22-Jun-15 9:25am    
ok thanks buddy ... keep tracking and give me a solution.
Which version of IE?
hariprashanth11 23-Jun-15 1:03am    
IE all the versions.
I have created this fiddle for you. See if this is working or not. It was working for me in IE.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900