How to automatically fill our current location in the Places TextArea for my MVC application ?

Total Post:8

Points:56
C#
 205  View(s)
Ratings:
Rate this:

Fill user location automatically in Place/Location text field. 

How to automatically fill our current location in the Places TextArea for my MVC application ?

  1. Post:46

    Points:324
    Re: How to automatically fill our current location in the Places TextArea for my MVC application ?

    Fill location in the text field via automatically 

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script type="text/javascript" src="https://code.jquery.com/jquery-2.2.3.js"></script>
    </head>
    <body>
     <span><b> Current Address:</b></span>
       <div id="address"></div>
            <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
        <script type="text/javascript">
            $(function () {
                CurrentLocation();
            });
            function CurrentLocation() {
                if (navigator.geolocation) {
                    navigator.geolocation.getCurrentPosition(showPosition);
                } else {
                    alert("Geolocation is not supported by this browser.");
                }
            }
            function showPosition(position) {
                latitude = position.coords.latitude;
                longitude = position.coords.longitude;
                var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                var geocoder = geocoder = new google.maps.Geocoder();
                geocoder.geocode({ 'latLng': latlng }, function (results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        if (results[1]) {
                            document.getElementById("address").innerHTML = results[1].formatted_address;
                        }
                    }
                });
            }
        </script>
    </body>
    </html>
    

    On Mozilla browser 

    How to automatically fill our current location in the Places TextArea for my MVC application ?

    On Chrome

    How to automatically fill our current location in the Places TextArea for my MVC application ?

    Result

    How to automatically fill our current location in the Places TextArea for my MVC application ?

Answer