amapHelper.js
1.24 KB
define(["mUtil","amap"],function(o){return{convertPoint:function(e,n,a){var t="";switch(n=Number(n)){case 2:t="baidu";break;case 3:t="gps"}""!=t?AMap.convertFrom(e,t,function(e,n){if("ok"===n.info){var t=n.locations[0];a&&a([t.lng,t.lat])}else o.console.error("convert to GD coordinate failed.")}):a&&a(e)},getAddress:function(r,o,c){AMap.plugin("AMap.Geocoder",function(){(new AMap.Geocoder).getAddress([r,o],function(e,n){var t,a;n=n.regeocode||{},t=n.formattedAddress,a=n.addressComponent||{},c&&c({status:"1",errMsg:"",lng:r,lat:o,addr:t,province:a.province,city:a.city,district:a.district,street:a.street,streetNumber:a.streetNumber})})})},placeSearch:function(a,r){AMap.plugin("AMap.PlaceSearch",function(){(new AMap.PlaceSearch).search(a,function(e,n){if("OK"===n.info){var t=n.poiList.pois[0].location;r&&r([t.lng,t.lat])}else o.getLabel(5297,"地址:#ADDR# 没有解析到结果!",function(e){o.console.error(e.replace("#ADDR#",a))})})})},searchNearBy:function(e,n,t,a){AMap.plugin("AMap.PlaceSearch",function(){new AMap.PlaceSearch({pageSize:Number(t)}).searchNearBy("",e,Number(n)||100,function(e,n){var t="OK"===n.info?n.poiList.pois:[];a&&a(t.map(function(e){return{point:{lng:e.location.lng,lat:e.location.lat},title:e.name,address:e.address}}))})})}}});