geo*_*liu 7 javascript google-maps ios cordova
设置是PhoneGap应用上的Google Maps Javascript API(v3),我设置了自动完成功能:
var that = this
this.autocomplete = new google.maps.places.Autocomplete(domNode)
this.listener = google.maps.event.addListener(
this.autocomplete, 'place_changed', function (place) {
var place = that.autocomplete.getPlace()
...
}
})
Run Code Online (Sandbox Code Playgroud)
此代码适用于我的Android版本和浏览器.问题是我在iOS下运行它.我在搜索框中键入一个字符串,显示自动填充结果,但单击其中一个只会关闭下拉列表,但结果不会填充到搜索框中.听众也不会开火.Javascript控制台上没有显示错误.
这是Google的所有代码,所以我对如何调试感到茫然.任何帮助,将不胜感激.谢谢!
在我的一个项目中,我一直在 iPhone 上遇到同样的问题,经过几个小时的调查,发现问题是由fastclicklib.lib 引起的。
FastClick.prototype.onTouchEnd = function(event) {
...
if (!this.needsClick(targetElement)) {
event.preventDefault();
this.sendClick(targetElement, event);
}
return false;
};
FastClick.prototype.needsClick = function(target) {
'use strict';
switch (target.nodeName.toLowerCase()) {
// Don't send a synthetic click to disabled inputs (issue #62)
case 'button':
case 'select':
case 'textarea':
if (target.disabled) {
return true;
}
break;
case 'input':
// File inputs need real clicks on iOS 6 due to a browser bug (issue #68)
if ((this.deviceIsIOS && target.type === 'file') || target.disabled) {
return true;
}
break;
case 'label':
case 'video':
return true;
}
return (/\bneedsclick\b/).test(target.className);
};
Run Code Online (Sandbox Code Playgroud)
因为.pac-container只有divand span,FastClick假设它不可点击并调用preventDefault,为了克服这个问题,我needsclick为所有.pac-*元素添加了类