【问题标题】:Re-Load Google place data from cookie从 cookie 重新加载 Google 地方数据
【发布时间】:2016-05-31 04:44:08
【问题描述】:

我已经实现了http://www.aspsnippets.com/Articles/Google-Places-AutoComplete-example-without-using-Maps.aspx的一个版本

效果很好!

我现在要做的是从 cookie 中提取最后使用的位置。在 cookie 中,我存储了谷歌在选择正确的项目后放置的文本框中的文本。这是这个地方的全名和街道。我可以使用文本数据重新填充文本框,但无法在 Google 中识别它。我尝试使用

触发更改事件
$('#txtLocation').trigger('change');

这似乎没有开火。

当我点击预先填充的字段时,Google 会在列表中为我提供正确的条目,然后我需要点击该条目。有没有人有好的方法来做到这一点?

【问题讨论】:

    标签: javascript asp.net vb.net cookies google-places


    【解决方案1】:

    您可以通过在文本字段上使用它来触发谷歌自动完成:

    google.maps.event.trigger($('#txtLocation')[0], 'focus');
    

    附加信息:这是使用谷歌地图自动完成功能的一种方式,根本不需要文本字段:

    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();
        });
      }
    });
    

    【讨论】:

    • 这太好了,谢谢!你答案的第二部分是我正在寻找的。与 Google 页面中的多个功能相比,我喜欢它有多小。
    猜你喜欢
    • 2017-04-10
    • 1970-01-01
    • 2019-01-02
    • 2011-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-12
    • 2013-09-10
    相关资源
    最近更新 更多