如何在值更改后更改Google地图自动填充字段的值?更改Google地图自动填充字段的值
我的最终愿望是只显示在这个领域的地址,以及城市,州等在不同的领域。
如http://jsbin.com/wiye/2/(脚本重复以下)所示,我更改了该值,但稍后又改回。
show just the street address in google.maps.event.addListener()问同样的问题,但它不再出现工作。 Change the value in textbox of a google map autocomplete也提出同样的问题,但没有足够的答案。
谢谢
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Places search box</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js" type="text/javascript"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
<script>
$(function(){
var input_auto = document.getElementById('input_auto');
autocomplete = new google.maps.places.Autocomplete(input_auto,{types: ['geocode'],radius: 10});
google.maps.event.addListener(autocomplete, 'place_changed', function() {
setTimeout(function(){$('#input_auto').val('yyy');},50);
alert('pause1');
console.log(autocomplete,input_auto);
input_auto.value='xxx';
//autocomplete.set('xxx');
//autocomplete.setValues('xxx');
alert('pause2');
});
});
</script>
</head>
<body>
<input id="input_auto" type="text">
</body>
</html>
可能的重复http://stackoverflow.com/questions/21617795/google-maps-autocomplete-bounces-back-already-cleared-text-odd-odd-odd/21620115#21620115 –
@ Dr.Molle你认为这是海报所说的“错误”,还是Google眼中的一个特征? – user1032531
我会称之为不完整的实现。与打字相比,改变输入值的方法更多(例如,以编程方式,但也可以例如剪切/粘贴或表单的重置方法),API应该考虑到这些可能性。 –