Find Latitude Longitude

HTML Code

<html>
    <body>
        Place Name <input id="gadres" placeholder="Type a place name" required="" type="text">
        <input type="button" value="find" id="findLatLng"/><br/><br/>
        Latitude <input name="lat" id="lat" placeholder="lat coordinate" type="text">
        Longitude <input name="lng" id="lng" placeholder="long coordinate" type="text">
    </body>
    <script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
        $(function(){
            $("#findLatLng").click(function(){
                var geocoder = new google.maps.Geocoder();
                geocoder.geocode({
                    'address': $("#gadres").val()
                }, function(results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        $('#lat').val(results[0].geometry.location.lat().toFixed(6));
                        $('#lng').val(results[0].geometry.location.lng().toFixed(6));
                    } else {
                        alert("Lat and long cannot be found.");
                    }
                });
                return false;
            });
        });
    </script>
</html>

Result -




                                                      After enter location and click of find

Comments