Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

google maps autocomplete js events

autocomplete.addListener("place_changed", () => {})
Comment

javascript google map place autocomplete

<html>
<head>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places"></script>
    <script>
        function initialize() {
          var input = document.getElementById('searchTextField');
          var autocomplete = new google.maps.places.Autocomplete(input);
            google.maps.event.addListener(autocomplete, 'place_changed', function () {
                var place = autocomplete.getPlace();
                document.getElementById('city2').value = place.name;
                document.getElementById('cityLat').value = place.geometry.location.lat();
                document.getElementById('cityLng').value = place.geometry.location.lng();
            });
        }
        google.maps.event.addDomListener(window, 'load', initialize);
    </script>
</head>
<body>
    <input id="searchTextField" type="text" size="50" placeholder="Enter a location" autocomplete="on" runat="server" />  
    <input type="hidden" id="city2" name="city2" />
    <input type="hidden" id="cityLat" name="cityLat" />
    <input type="hidden" id="cityLng" name="cityLng" />
</body>
</html>
Comment

javascript google map place autocomplete

<html>
<head>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places"></script>
    <script>
        function initialize() {
          var input = document.getElementById('searchTextField');
          var autocomplete = new google.maps.places.Autocomplete(input);
            google.maps.event.addListener(autocomplete, 'place_changed', function () {
                var place = autocomplete.getPlace();
                document.getElementById('city2').value = place.name;
                document.getElementById('cityLat').value = place.geometry.location.lat();
                document.getElementById('cityLng').value = place.geometry.location.lng();
            });
        }
        google.maps.event.addDomListener(window, 'load', initialize);
    </script>
</head>
<body>
    <input id="searchTextField" type="text" size="50" placeholder="Enter a location" autocomplete="on" runat="server" />  
    <input type="hidden" id="city2" name="city2" />
    <input type="hidden" id="cityLat" name="cityLat" />
    <input type="hidden" id="cityLng" name="cityLng" />
</body>
</html>
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to fill array with consecutive numbers javascript 
Javascript :: how to check if a javascript object is empty 
Javascript :: joi validation 
Javascript :: jquery click not working on dynamic content 
Javascript :: sequelize where more than 
Javascript :: javascript wait for dom 
Javascript :: laravel using react 
Javascript :: layout nextjs 
Javascript :: npm react dom routing 
Javascript :: findone sequelize 
Javascript :: reduce array to object javascript 
Javascript :: transpose of the matrix in javascript 
Javascript :: joi custom error 
Javascript :: jquery onload function for div 
Javascript :: debounchow use input debounce in javascript vue.js 
Javascript :: install ckeditor 5 for react js 
Javascript :: js tab character 
Javascript :: javascript check if element is visible on screen 
Javascript :: accept Post with no midleWare express 
Javascript :: js largest number in array 
Javascript :: install latest electron 
Javascript :: ajax upload image 
Javascript :: LF would be replaced by CRLF in package-lock.json 
Javascript :: compare two dates in javascript yyyy-mm-dd 
Javascript :: javascript eval passing variable 
Javascript :: cypress check attribute for each element 
Javascript :: sweet alert in java Script 
Javascript :: angular ngfor counter 
Javascript :: javascript replace last occurrence of a letter 
Javascript :: how to remove whitespace only from first position of string js 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =