重新加载 Google 放置来自 cookie 的数据
Re-Load Google place data from cookie
我实现了http://www.aspsnippets.com/Articles/Google-Places-AutoComplete-example-without-using-Maps.aspx
的一个版本
效果很好!
我现在要做的是从 cookie 中提取上次使用的位置。在 cookie 中,我存储了 Google 在选择了正确的项目后放在那里的文本框的文本。这是该地点的全名和街道。我可以用文本数据重新填充文本框,但我无法在 Google 中识别它。我尝试使用
触发更改事件
$('#txtLocation').trigger('change');
似乎没有火。
当我单击预填充字段时,Google 会在列表中提供正确的条目,然后我需要单击该条目。有谁有好的方法吗?
您可以通过在文本字段上使用这个来触发 google 自动完成:
google.maps.event.trigger($('#txtLocation')[0], 'focus');
附加信息:这是使用 Google-Maps 的自动完成功能的一种方法,根本不需要文本字段:
var locationService = new google.maps.places.AutocompleteService(null, {
types: ['geocode']
});
locationService.getPlacePredictions({
input: "mylocation"
}, function(predictions, status) {
if(status=='OK' && predictions.length > 0 && predictions[0]) {
var s = new google.maps.places.PlacesService($('<div>')[0]);
s.getDetails({
reference: predictions[0].reference
}, function(details, status) {
var latitude = details.geometry.location.lat();
var longitude = details.geometry.location.lng();
});
}
});
我实现了http://www.aspsnippets.com/Articles/Google-Places-AutoComplete-example-without-using-Maps.aspx
的一个版本效果很好!
我现在要做的是从 cookie 中提取上次使用的位置。在 cookie 中,我存储了 Google 在选择了正确的项目后放在那里的文本框的文本。这是该地点的全名和街道。我可以用文本数据重新填充文本框,但我无法在 Google 中识别它。我尝试使用
触发更改事件$('#txtLocation').trigger('change');
似乎没有火。
当我单击预填充字段时,Google 会在列表中提供正确的条目,然后我需要单击该条目。有谁有好的方法吗?
您可以通过在文本字段上使用这个来触发 google 自动完成:
google.maps.event.trigger($('#txtLocation')[0], 'focus');
附加信息:这是使用 Google-Maps 的自动完成功能的一种方法,根本不需要文本字段:
var locationService = new google.maps.places.AutocompleteService(null, {
types: ['geocode']
});
locationService.getPlacePredictions({
input: "mylocation"
}, function(predictions, status) {
if(status=='OK' && predictions.length > 0 && predictions[0]) {
var s = new google.maps.places.PlacesService($('<div>')[0]);
s.getDetails({
reference: predictions[0].reference
}, function(details, status) {
var latitude = details.geometry.location.lat();
var longitude = details.geometry.location.lng();
});
}
});