//根据选择框或输入框获取地址 var _area={ //keyword:'', _areaLists:$(".areaLists"), _address:$("#address"), unChecked:function(val){ return (val==''||typeof (val)=='undefined'||val==null|| val=='省份'||val=='地级市'||val=='市、县级市')?false:true; }, list:function(){ //console.log(_areaLists.length); var _joinArea=''; for(var i=0;i<this._areaLists.length;i++){ if(_area.unChecked(this._areaLists[i].value)){ _joinArea+=this._areaLists[i].value; } } if(_area.unChecked(this._address.val())){ _joinArea+=' '+this._address.val(); //_joinArea=this._address.val(); console.log('here'); } //console.log(_joinArea); return _joinArea; }, init:function(){ //绑定百度地图 var _this=_area.list(); console.log('_this='+_this); //定义local var local = new BMap.LocalSearch(map, { renderOptions:{map: map,autoViewport: true} }); local.setSearchCompleteCallback(function (searchResult) { var poi = searchResult.getPoi(0); //document.getElementById("result_").value = poi.point.lng + "," + poi.point.lat; map.centerAndZoom(poi.point, 11); gc.getLocation(poi.point, function(rs){ showLocationInfo(poi.point, rs); }); }); local.search(_this); } }
总结:
完整demo