当前位置: 动力学知识库 > 问答 > 编程问答 >

Google Places Autocomplete issue on iOS7 (webview)

问题描述:

I currently have an issue implementing a simple Google Places Autocomplete input in a webview.

My issue seems to be related to a bug in ios7 where the blur event is triggered before the place_changed has been fired, thus the input field doesn't take the chosen value.

Here is the code (part of an AngularJS directive):

 var newAutocomplete = function () {

scope.gPlace = new google.maps.places.Autocomplete(element[0], opts);

google.maps.event.addListener(scope.gPlace, 'place_changed', function () {

scope.$apply(function () {

var place = scope.gPlace.getPlace();

if (!place || !place.geometry) {

return;

}

scope.location = {

coords: {

lat: place.geometry.location.lat(),

lng: place.geometry.location.lng()

},

address: element.val()

};

});

});

};

Any idea how to handle this? Delaying the onBlur event?

Thanks in advance.

[SELF-ANSWERED]

I just found out the problem was related to the use of the FastClick library.

This is what needs to be added in the page to make it work:

$(document).on({

'DOMNodeInserted': function() {

$('.pac-item, .pac-item span', this).addClass('needsclick');

}

}, '.pac-container');

Thanks to can't tap on item in google autocomplete list on mobile for the solution!

分享给朋友:
您可能感兴趣的文章:
随机阅读: