我正在使用 Google Maps AutoComplete 界面在用户键入时自动查找位置。它适用于我测试过的所有浏览器(Chrome、FireFox、iOS 和更新的 Android 设备),Windows Phone 除外。
在 Windows 手机上,places_changed 事件似乎没有被触发,文本框也不会像在其他浏览器上那样自动更新。
这是一个简化的场景,演示了表单上的单个文本框:
<div class="container" style="padding: 40px">
<label>Enter a location</label>
<input id="location" value="" class="form-control" />
</div>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true&libraries=places">
</script>
<script>
var el = document.getElementById('location');
var autocomplete = new google.maps.places.Autocomplete(el);
google.maps.event.addListener(autocomplete, 'place_changed', function () {
var place = autocomplete.getPlace();
if (place.geometry.location)
// delay setting the value - otherwise maps uses default always
setTimeout(function() { el.value = place.name; }, 200);
});
</script>
你可以试试这个: http ://embed.plnkr.co/kAwU0Fl97nEQr5HhxOTH/preview
它在所有浏览器中都能正常工作(包括 IE 11,它据称使用与 Windows Phone 8 相同的渲染引擎),但在 Windows Phone 上会弹出下拉框,但不会触发文本框的自动更新,也不会触发显式事件代码仅使用名称更新文本。
有没有办法解决这个问题?