Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <input name="location" type="text" id="location">
- $(document).ready(function() {
- ...
- var autocomplete = new google.maps.places.Autocomplete($('#location')[0]);
- addLocationChangeListener(autocomplete);
- ...
- $("form").submit(function(e){
- doValidations(e, autocomplete);
- });
- });
- // When user changes location, update map coordinates
- function addLocationChangeListener(autocomplete) {
- autocomplete.addListener('place_changed', function() {
- console.log("PLACE CHANGED");
- var place = autocomplete.getPlace();
- console.log("PLACE: ", place);
- console.log("---------------------");
- if(place && place.geometry) {
- ... // save stuff
- }
- ...
- }); // End Add Listener
- }
- $("#location").on("blur", function() {
- if(autocomplete.getPlace() === undefined) {
- //display error, prevent form submission
- }
- });
Add Comment
Please, Sign In to add comment