Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

google maps places autocomplete api

<input type="text"required id="autocomplete">
<script>
function initAutocomplete() {
   new google.maps.places.Autocomplete(
          (document.getElementById('autocomplete')),
          {types: ['geocode']}
   );
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=&libraries=places&callback=initAutocomplete"
                async defer></script>
Comment

google maps autocomplete region returned types

// Region will return the following types

locality
sublocality
postal_code
country
administrative_area_level_1
administrative_area_level_2
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

google search autocomplete api example

<div id="output"></div>

<script>
/* this function shows the raw data */
function myAmazingFunction(data){
    document.getElementById('output').innerHTML = data;
}
</script>

<script src="https://www.google.com/complete/search?client=hp&hl=en&sugexp=msedr&gs_rn=62&gs_ri=hp&cp=1&gs_id=9c&q=a&xhr=t&callback=hello&callback=myAmazingFunction"></script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: change index array javascript 
Javascript :: jquery find div with data attribute value 
Javascript :: npm registry 
Javascript :: .split is not a function 
Javascript :: javascript simulate click on element 
Javascript :: javascript reduce fraction 
Javascript :: convert result of .innerHTML to number on javascript 
Javascript :: js sort by date 
Javascript :: javascript folder dynamic import 
Javascript :: remove duplicates objects from array javascript 
Javascript :: nodejs get param cli 
Javascript :: filter javascript 
Javascript :: iterate through object array javascript 
Javascript :: SEQUELIZE OR 
Javascript :: How to Use the toUpperCase() String Method in javascript 
Javascript :: character from character code js 
Javascript :: jquery append table row 
Javascript :: how to turn number into string javascript 
Javascript :: Date gethours js 
Javascript :: exponent in javascript 
Javascript :: use eslint in vscode 
Javascript :: firebase read data javascript 
Javascript :: javascript wait async 
Javascript :: js get form inputs 
Javascript :: using dto in node js 
Javascript :: axios get data 
Javascript :: localdatetime json 
Javascript :: factorial javascript function 
Javascript :: react usestate functional update 
Javascript :: push an property and value to an object in javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =