0

好的,所以我构建了一个工作(几乎)地理编码器,它接受地址或纬度/经度组合,并建议结果见此处:

$(this).autocomplete({

        source:function (request, response) {

            if (geocoder == null) {
                geocoder = new google.maps.Geocoder();
            }
            geocoder.geocode({'address':request.term }, function (results, status) {

                if (status == google.maps.GeocoderStatus.OK) {
                    var searchLoc = results[0].geometry.location;
                    var lat = results[0].geometry.location.lat();
                    var lng = results[0].geometry.location.lng();
                    var latlng = new google.maps.LatLng(lat, lng);
                    var bounds = results[0].geometry.bounds;

                    geocoder.geocode({'latLng':latlng}, function (results1, status1) {
                        if (status1 == google.maps.GeocoderStatus.OK) {
                            if (results1[1]) {
                                response($.map(results1, function (loc) {
                                    return {
                                        label:loc.formatted_address,
                                        lat:lat,
                                        lng:lng,
                                        value:loc.formatted_address,
                                        bounds:loc.geometry.bounds
                                    }
                                }));
                            }
                        }
                    });
                }
            });
        },

并且 90% 的时间它都非常有效。但是,我现在注意到有时它在弹出列表中返回的第一项是不可点击的。我已经为变量设置了日志,status并注意到它偶尔是ZERO_RESULTQUERY_LIMIT_REACHED。在这两种情况下,列表都会加载值,并且列表中的所有内容都是可选的,除了第一个。任何可能的解决方案的想法?

4

1 回答 1

0

看起来有些实例bounds被 API 遗漏了,因此在我的代码中定义为undefined. 这导致代码进一步出现 javascript 问题,并阻止满足条件。看起来甚至不需要正确构建地图,我已经解决了我的问题......

于 2013-03-20T20:26:05.297 回答