【问题标题】:How to get the zip-code using google-maps-api-3 in a text input autocomplete如何在文本输入自动完成中使用 google-maps-api-3 获取邮政编码
【发布时间】:2014-08-25 12:52:38
【问题描述】:

如何在地址限制的情况下从自动完成文本输入中获取结果?

我的意思是,我有一个文本输入,我需要获取这个地方的邮政编码,但是当我写一个地址时,它给了我很多选项,公共场所,一般场所等。只有街道(没有街道前缀)和完整的街道名称给了我邮政编码。

问题是我只有在写前缀“street”时才能得到邮政编码,否则不起作用,这就是为什么我想将自动完成结果限制为只有地址。

示例:

Writting: Piccadilly Circus 5 --> 我得到了邮政编码, 5 Piccadilly Circus, Soho, Londres W1D 7ET, Reino Unido

写作:皮卡迪利广场 --> 我找不到邮政编码 皮卡迪利广场、伦敦 W1J、Reino Unido

有什么想法吗?谢谢!

link_code_here

<div class="form-group">
    <label for="txtAddress">Write your address:</label>
    <input type="text" id="geocomplete" name="txtAddress"/>
</div>

    $(function () {
    $("#geocomplete").geocomplete({
        types:["geocode", "establishment"]
    })
    .bind("geocode:result", function (event, result) {
        //$.log("Result: " + result.formatted_address);
        alert("Result: " + result.formatted_address);
    })
    .bind("geocode:error", function (event, status) {
        alert("ERROR: " + status);
    })
    .bind("geocode:multiple", function (event, results) {
       alert("Multiple: " + results.length + " results found");
    });
});

【问题讨论】:

  • 恐怕你无能为力

标签: jquery google-maps google-maps-api-3 autocomplete


【解决方案1】:

不知道能不能帮忙

    $("#geocomplete").geocomplete(
    { 
       types:["geocode", "establishment"]
    }
).bind("geocode:result", function(event, result){

  results = result.address_components;

  $.each(results, function( index, value ) {
     if(value.types == 'postal_code'){

         console.log(value.long_name); // here you get the zip code  
     }
  });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-15
    • 2011-07-31
    • 2020-04-02
    相关资源
    最近更新 更多