简体   繁体   中英

Google locations automatic is not working in my php page

I am using google automatic location api but it is not showing on the page..Can you guys figure out whats wrong in the code.

My script is :

<script>
        function init() {
            var input = document.getElementById('locationTextField');
            var input2 = document.getElementById('locationTextField2');

             var autocomplete = new google.maps.places.Autocomplete(input);
             var autocomplete = new google.maps.places.Autocomplete(input2);

        }

        google.maps.event.addDomListener(window, 'load', init);
    </script>

My html code is this :

     <input type="text" id="locationTextField" placeholder="Source Location"/>
       <input type="text" id="locationTextField2" placeholder="Destination Location"/>

Please load your script with valid api key in your site,

<script src="https://maps.googleapis.com/maps/api/js?key=<YOUR_API_KEY>&v=3.exp&sensor=false&libraries=places"></script>

Here is example (without api key for demo only):

 function initialize() { new google.maps.places.Autocomplete((document.getElementById('source')), { types: ['geocode'] }); new google.maps.places.Autocomplete((document.getElementById('dest')), { types: ['geocode'] }); } google.maps.event.addDomListener(window, 'load', initialize); 
 <script src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places&dummy=.js"></script> <input id="source" name="source" value="" type="text" size="50" placeholder="Source" /> <input id="dest" name="dest" value="" type="text" size="50" placeholder="Destincation" /> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM