【问题标题】:Geocoder v3 Autocomplete HotelGeocoder v3 自动完成酒店
【发布时间】:2012-12-22 10:25:03
【问题描述】:

我们正在运营一个网站 (www.taxileader.net/taxi-tegel.html),人们可以在该网站上预订从机场到目的地的出租车。

要预订和计算通常是机场的起始地址(我们的数据库中已经存在纬度/经度)与目的地之间的距离,我们使用谷歌地图 v3

在“目的地字段”中,我们已经有一个自动完成功能,可以从客户填写的地址中提取邮政编码(或邮政编码),但我们还需要他们找到酒店的邮政编码。

我们用来获取地址信息的 API 调用是 geocoder v3,这是错误的还是我们需要添加其他东西来查找酒店?

$("#txt_indirizzo").autocomplete({
    //This bit uses the geocoder to fetch address values
    source : function(request, response) {
        geocoder.geocode({
            'address' : request.term,
            'bounds' : bound
        }, function(results, status) {
            response($.map(results, function(item) {
                var zip = '';
                for (var i in item.address_components) {
                    if (item.address_components[i].types[0] == 'postal_code' || item.address_components[i].types[1] == 'postal_code') {
                        zip = item.address_components[i].long_name;
                    }
                }
                if (zip == '') {
                    return;
                } else {
                    return {
                        value : item.formatted_address,
                        latitude : item.geometry.location.lat(),
                        longitude : item.geometry.location.lng(),
                        zip : zip
                    }
                }

            }));
        })
    },
    //This bit is executed upon selection of an address
    select : function(event, ui){
        if (tipoDiTrasf == 2) {
            return;
        }

        chk_txt_indirizzo = true;
        if (ui.item.zip != '') {

            chkPostcode(ui.item.zip, ui.item.latitude, ui.item.longitude, ui.item.value, '#txt_indirizzo');

        } else {
            alert('Questo non è un indirizzo valido');
            setTimeout('$("#txt_indirizzo").val("")', 5);
        }
        tab(1);
    },
    change : function() {
        if (!chk_txt_indirizzo) {
            $("#txt_indirizzo").val('').data("autocomplete").term = "";
            zip_indirizzo = pointLat2 = pointLon2 = setIndirizzo = false;
            putondinNam();

        }
    }
});

至少有没有办法让谷歌地图只自动填充到城市?

我的意思是在“城市字段”中,我们只想显示城市而不是地址

非常感谢

【问题讨论】:

  • 我们已经使用地理编码从客户写的地址中提取 zip,但是在目标字段中,我们需要使用 google 自动完成显示酒店列表并从中提取 zip,只是为了内部计算。
  • 我建议您将其放入问题中。而不仅仅是这句话。你必须解决这个问题。这里的问题应该显示您尝试过什么,究竟遇到了什么问题,您已经采取了哪些措施来消除它以及结果如何。刚才你的问题看起来很不确定。只是因为你是这里的首发,它没有因为它的模糊性而关闭。并在那里放置标签。例如,您的语言是什么?有成千上万个。

标签: autocomplete geocode


【解决方案1】:

【讨论】:

  • 您好,感谢您的回答,我们已经在您的一个链接gerger.co/blog/2011/02/17/… 之前使用过所有其他链接都没有显示此类酒店的任何营业地点。地理编码器只接受地址,我们需要一个作为 GETLOCAL 的 API(如果我没记错的话,谷歌地图 v2)来获取像酒店这样的商业地点
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-03
  • 2018-04-09
  • 1970-01-01
  • 2012-08-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多