Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
HI friends i am getting user current location and also able to locate it on google map , but i have a problem , i am unable to find out address of that coordinate in human readable form , i have googled very much and find no solution , i am posting my code any help will be appreciated , thank you ...


XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get User Current Location using Google Map Geolocation API Service in asp.net website</title>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC6v5-2uaq_wusHDktM9ILcqIrlPtnZgEk&sensor=false"> </script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"> </script>
<script type="text/javascript">
    if (navigator.geolocation) {

        debugger;
        navigator.geolocation.getCurrentPosition(success);
    } else {
        alert("Geo Location is not supported on your current browser!");
    }
    function success(position) {
        debugger;
        var lat = position.coords.latitude;
        var long = position.coords.longitude;
        var city = position.coords.locality;
       // alert(position.coords.address);
        var myLatlng = new google.maps.LatLng(lat, long);
        var myOptions = {
            center: myLatlng,
            zoom: 12,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        var marker = new google.maps.Marker({
            position: myLatlng,
            title: "lat: " + lat + " long: " + long

        });

        marker.setMap(map);
        var infowindow = new google.maps.InfoWindow({ content: "<b>User Address</b><br/> Latitude:" + lat + "<br /> Longitude:" + long + "" });
        infowindow.open(map, marker);
      //  alert(marker.position.text);
    }
</script>
</head>
<body >
<form id="form1" runat="server">
<div id="map_canvas" style="width: 500px; height: 400px"></div>
</form>
</body>
</html>
Posted
Updated 4-Jun-15 5:27am
v2
Comments
Afzaal Ahmad Zeeshan 4-Jun-15 12:28pm    
What do you mean by human readable form? Perhaps, Google Maps API would have a function to provide the actual Address (from their directory) for the latitude and longitude data that you would provide them with.
GDdixit 4-Jun-15 22:56pm    
i mean by this when i getting user current location , it will provide me geo code and point on map . Actually i need to save address in database so i want address also with geo code .

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