我正在尝试修改jQuery Addresspicker widget,以便除了Google Maps Geocoder结果外,还可以从一系列自定义数据中返回自动完成结果。目标是使用户能够搜索商店名称,然后在地图上居中,或者搜索街道/城市/地区名称,这些名称将显示在未修改的小部件中。
问题是,我无法将小部件保存为本地/方法变量。我的猜测是它与封闭有关,我已经四处寻找解决方案,但到目前为止仍处于黑暗中。
自定义数据数组在widget init期间设置:
var marker = createCustomDataArray();
var addresspicker = $( "#searchbox" ).addresspicker({
mapOptions: {
zoom: 17,
regionBias: "id",
center: pos,
scrollwheel: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
componentRestrictions: { country: "id" },
types: ['geocode']
},
elements: {
map: "#mapholder",
lat: "#lat",
lng: "#lng",
locality: '#locality',
country: '#country'
},
customData: marker
})
这是经过修改的脚本:
$.widget( "ui.addresspicker", {
options: {
appendAddressString: "",
draggableMarker: true,
regionBias: "id",
mapOptions: {
zoom: 12,
center: new google.maps.LatLng(-5, 106.84517200000005),
scrollwheel: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
},
elements: {
map: false,
lat: false,
lng: false,
locality: false,
country: false,
type: false
},
customData: null
},
setCustomData: function(data) {
this.customData = data;
return 42;
},
_create: function() {
this.geocoder = new google.maps.Geocoder();
this.element.autocomplete({
source: $.proxy(this._geocode, this),
focus: $.proxy(this._focusAddress, this),
select: $.proxy(this._selectAddress, this)
});
this.lat = $(this.options.elements.lat);
this.lng = $(this.options.elements.lng);
this.locality = $(this.options.elements.locality);
this.country = $(this.options.elements.country);
this.type = $(this.options.elements.type);
if (this.options.elements.map) {
this.mapElement = $(this.options.elements.map);
this._initMap();
}
this.setCustomData(this.options.customData);
},
有什么想法吗?