Display marker on Google Maps on Places AutoComplete selection in JavaScript

nauna
 
on Jan 29, 2021 11:29 PM
805 Views

I have this auto complete code. I want to have

1. As the user select the address, it’s instantly show in google map below

2. Then in google map user can also adjust the location and the same adjusted location updated in textbox above

Please advice

    <script type="text/javascript">
        google.maps.event.addDomListener(window, 'load', function () {
        var places = new google.maps.places.Autocomplete(document.getElementById('<%=txtpostcode.ClientID%>'));
            google.maps.event.addListener(places, 'place_changed', function () {
                var place = places.getPlace();
                var address = place.formatted_address;
                var latitude = place.geometry.location.lat();
                var longitude = place.geometry.location.lng();
                var mesg = "Address: " + address;
                mesg += "\nLatitude: " + latitude;
                mesg += "\nLongitude: " + longitude;
                //alert(mesg);
            });
        });
    </script>

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download