【发布时间】:2014-03-06 16:59:25
【问题描述】:
更改值后如何更改 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>
【问题讨论】:
-
@Dr.Molle 您认为这是该海报所说的“错误”,还是 Google 眼中的功能?
-
我认为它是一个不完整的实现。更改输入值的方法比键入更多(例如,以编程方式,但也例如剪切/粘贴或表单的重置方法),API 应考虑这些可能性。
标签: javascript jquery google-maps google-maps-api-3 google-maps-autocomplete