Google maps api 3 如何格式化GooglePlaces推送到文本框中的自动完成文本
我在一个文本框上使用Google places AutoComplete,它基本上是工作的,选择位置并将它们填充到文本框中 问题是,我只想填充选择名称,而不是自动完成列表生成的列表中的全名+地址格式。我似乎找不到一种方法来覆盖文本框中的内容Google maps api 3 如何格式化GooglePlaces推送到文本框中的自动完成文本,google-maps-api-3,autocomplete,google-places-api,Google Maps Api 3,Autocomplete,Google Places Api,我在一个文本框上使用Google places AutoComplete,它基本上是工作的,选择位置并将它们填充到文本框中 问题是,我只想填充选择名称,而不是自动完成列表生成的列表中的全名+地址格式。我似乎找不到一种方法来覆盖文本框中的内容 var $name = $("#txtName"); $name.focus(); var autocomplete = new google.maps.places.Autocomplete($name[0]); goog
var $name = $("#txtName");
$name.focus();
var autocomplete = new google.maps.places.Autocomplete($name[0]);
google.maps.event.addListener(autocomplete, 'place_changed', function () {
var place = autocomplete.getPlace();
// explicitly update model
// but doesn't display in UI
$scope.locationData.Name = place.name;
// explicitly update the input box - doesn't update UI
$name.val(place.name);
return false; // doesn't work - updates UI
});
基本上,我想做的是自己接管输入框文本赋值,自己完成赋值并强制autocomplete不设置文本框值
这可能吗 在短时间内设置该值
$('#NameBox').on('blur change', function () { $(this).val(place.name).off('blur change'); });
setTimeout(function () { $('#NameBox').val(place.name); }, 150);
使用.off()
允许用户根据需要编辑名称。如果希望仅允许places API名称,请删除.off()