【问题标题】:i want to find address by zipcode and selected country using google api我想使用 google api 按邮政编码和所选国家/地区查找地址
【发布时间】:2018-08-22 12:37:18
【问题描述】:

我正在使用 google api 获取带有邮政编码的地址及其完美的工作

但我想只限制选择国家/地区,我该怎么做?

这是我使用邮政编码获取地址的代码我如何在这个 api 中也通过国家/地区

var obj = {};
        obj.address = value;


        $.ajax({
            type: "GET",
            url: "https://maps.googleapis.com/maps/api/geocode/json",
            //  contentType: "application/json; charset=utf-8",
            dataType: 'json',
            data: obj,
            async: false,
            success: function (res) {
                console.log(res);
                getValueFromZipcode = res;
                assignData(getValueFromZipcode);
            },
            error: function (err) {
                callLoader(false);
                swal({
                    title: "Something Wents Wrong", text: "", type: "error",
                    showCancelButton: false, closeOnConfirm: true, confirmButtonText: "OK",
                }, function (isConfirm) {
                    window.location = "signin";
                });
                // console.log(err);
            }
        });

【问题讨论】:

标签: javascript ajax google-maps-api-3


【解决方案1】:
var country = 'IN';
var postal_code = 560068;

    $.ajax({
        type: "GET",
        url: "http://maps.googleapis.com/maps/api/geocode/json?sensor=true&components=country:"+country+"|postal_code:"+postal_code+"",
        //  contentType: "application/json; charset=utf-8",
        dataType: 'json',
        data: obj,
        async: false,
        success: function (res) {
            console.log(res);
        },
        error: function (err) {
            callLoader(false);
            swal({
                title: "Something Wents Wrong", text: "", type: "error",
                showCancelButton: false, closeOnConfirm: true, confirmButtonText: "OK",
            }, function (isConfirm) {
                window.location = "signin";
            });
            // console.log(err);
        }
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-10
    • 2016-07-20
    • 1970-01-01
    相关资源
    最近更新 更多