Guest User

Untitled

a guest
Oct 18th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. <input name="location" type="text" id="location">
  2.  
  3. $(document).ready(function() {
  4. ...
  5. var autocomplete = new google.maps.places.Autocomplete($('#location')[0]);
  6. addLocationChangeListener(autocomplete);
  7. ...
  8. $("form").submit(function(e){
  9. doValidations(e, autocomplete);
  10. });
  11.  
  12. });
  13.  
  14. // When user changes location, update map coordinates
  15. function addLocationChangeListener(autocomplete) {
  16. autocomplete.addListener('place_changed', function() {
  17. console.log("PLACE CHANGED");
  18. var place = autocomplete.getPlace();
  19. console.log("PLACE: ", place);
  20. console.log("---------------------");
  21. if(place && place.geometry) {
  22. ... // save stuff
  23. }
  24. ...
  25. }); // End Add Listener
  26. }
  27.  
  28. $("#location").on("blur", function() {
  29. if(autocomplete.getPlace() === undefined) {
  30. //display error, prevent form submission
  31. }
  32. });
Add Comment
Please, Sign In to add comment