Created
November 16, 2014 22:51
-
-
Save schoenobates/ef578a02ac8ab6726487 to your computer and use it in GitHub Desktop.
Fix for Google AutoComplete Places Javascript API on iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var autoElm = document.getElementById('elm-name'); | |
autocomplete = new google.maps.places.Autocomplete(autoElm); | |
google.maps.event.addListener(autocomplete, 'place_changed', function () { | |
var place = autocomplete.getPlace(); | |
if (!place.geometry) { | |
return; | |
} | |
instance.setCenter(place.geometry.location); | |
instance.setZoom(19); | |
autoElm.value = ''; | |
}); | |
// need to stop prop of the touchend event | |
if (navigator.userAgent.match(/(iPad|iPhone|iPod)/g)) { | |
setTimeout(function() { | |
var container = document.getElementsByClassName('pac-container')[0]; | |
container.addEventListener('touchend', function(e) { | |
e.stopImmediatePropagation(); | |
}); | |
}, 500); | |
} |
The original code worked for me:
// need to stop prop of the touchend event
if (navigator.userAgent.match(/(iPad|iPhone|iPod)/g)) {
setTimeout(function() {
var container = document.getElementsByClassName('pac-container')[0];
container.addEventListener('touchend', function(e) {
e.stopImmediatePropagation();
});
}, 500);
}
Thanks @schoenobates !
Works perfect! Thanks man!! I fking love you
It working on PC but not working on Android Mobile https://romanczujko.github.io/PayForDistance/
google.maps.event.addDomListener(window, 'load', function () {
var from_places = new google.maps.places.Autocomplete(document.getElementById('from_places'));
var to_places = new google.maps.places.Autocomplete(document.getElementById('to_places'));
google.maps.event.addListener(from_places, 'place_changed', function () {
var from_place = from_places.getPlace();
var from_address = from_place.formatted_address;
$('#origin').val(from_address);
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I am having the same issue. Tried the solutions above.
Does anybody has a different solution?