google maps api autocomplete works at localhost but does not work on the server -


i used google maps api autocomplete of places.

everythings works in localhost, when publish , upload on server, doesn't work...why happen? dropdown of places not show.

here html:

  <input type="text" id="autocomplete"> 

here js:

<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>   <script> var autocomplete;  function initialize() {    autocomplete = new google.maps.places.autocomplete(     (document.getelementbyid('autocomplete')), {       types: ['(cities)'],       componentrestrictions: { country: "ph" }     });   google.maps.event.addlistener(autocomplete, 'place_changed', function () {     fillinaddress();   });  }  placeparser = function(place){   result = {};   for(var = 0; < place.address_components.length; i++){     ac = place.address_components[i];     result[ac.types[0]] = ac.long_name;   }   return result; };   function fillinaddress() {    var place = autocomplete.getplace();   document.getelementbyid("latitude").value = place.geometry.location.lat();   document.getelementbyid("longitude").value = place.geometry.location.lng();    components = placeparser(place);  }  initialize(); 

there 3 issues

  1. you calling initialize without knowing if maps-api has been loaded, remove call of initialize , use callback-parameter of maps-api instead

  2. the maps-api requires key.
    seems there circumstances(undocumented) may work without key(i guess requests localhost , domains have been used maps-api before key has been required), domain doesn't match criteria, should/must use key

  3. (additionally)i call bug google: seems, use of places-library requires places api web service has been activated project( before sufficient activate maps javascript api )


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -