| | |
| | | |
| | | |
| | | object AMapKit { |
| | | |
| | | fun initLocation(context: Context, lisener: AMapLocationListener) { //初始化定位 |
| | | var mlocationClient = AMapLocationClient(context) |
| | | //初始化定位参数 |
| | |
| | | } |
| | | |
| | | fun moveCamera(aMap: AMap, start: LatLng?, end: LatLng?) { |
| | | var bounds: LatLngBounds? = null |
| | | if (start!!.latitude < end!!.latitude) |
| | | bounds = LatLngBounds(start, end) |
| | | else |
| | | bounds = LatLngBounds(end, start) |
| | | var bounds: LatLngBounds = getLatLngBounds(start!!,end!!) |
| | | val mCameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, 150) |
| | | aMap.animateCamera(mCameraUpdate, object : AMap.CancelableCallback { |
| | | override fun onFinish() { |
| | |
| | | sysErr("onCancel") |
| | | } |
| | | }) |
| | | } |
| | | |
| | | fun getLatLngBounds(start: LatLng, end: LatLng): LatLngBounds { |
| | | val b = LatLngBounds.builder() |
| | | b.include(LatLng(start.latitude, start.longitude)) |
| | | b.include(LatLng(end.latitude, end.longitude)) |
| | | return b.build() |
| | | } |
| | | |
| | | fun moveCamera(aMap: AMap, start: LatLng?, end: LatLng?, padd: Int) { |
| | |
| | | /*** |
| | | * 绘制圆形形围栏 |
| | | */ |
| | | fun drawFenceByCricle(context: Context, dPoint: DPoint,bg:Float, va1: GeoFenceListener) { |
| | | fun drawFenceByCricle(context: Context, dPoint: DPoint, bg: Float, va1: GeoFenceListener) { |
| | | val mGeoFenceClient = GeoFenceClient(context) |
| | | mGeoFenceClient.setActivateAction(GeoFenceClient.GEOFENCE_IN) |
| | | mGeoFenceClient.addGeoFence("", "",dPoint,bg,-1,"") |
| | | mGeoFenceClient.addGeoFence("", "", dPoint, bg, -1, "") |
| | | mGeoFenceClient.setGeoFenceListener(va1); |
| | | } |
| | | |
| | |
| | | fun drawFace(context: Context, aMap: AMap, latLngs: List<LatLng?>?): Polygon? { |
| | | var po = PolygonOptions().addAll(latLngs) |
| | | .fillColor(ContextCompat.getColor(context, R.color.l_transparent_10)).strokeColor( |
| | | Color.RED |
| | | ).strokeWidth(1f) |
| | | Color.RED |
| | | ).strokeWidth(1f) |
| | | return aMap.addPolygon(po) |
| | | } |
| | | |
| | | fun drawCricle(context: Context, aMap: AMap, latLng: LatLng,bg:Double): Circle? { |
| | | return aMap.addCircle(CircleOptions(). |
| | | center(latLng). |
| | | radius(bg). |
| | | fillColor(ContextCompat.getColor(context, R.color.l_transparent_10)). |
| | | strokeColor( Color.RED). |
| | | strokeWidth(1f)); |
| | | fun drawCricle(context: Context, aMap: AMap, latLng: LatLng, bg: Double): Circle? { |
| | | return aMap.addCircle( |
| | | CircleOptions().center(latLng).radius(bg) |
| | | .fillColor(ContextCompat.getColor(context, R.color.l_transparent_10)) |
| | | .strokeColor(Color.RED).strokeWidth(1f) |
| | | ); |
| | | } |
| | | |
| | | |
| | |
| | | /*** |
| | | * 逆地址编码 |
| | | */ |
| | | fun getAddress(context: Context,lat:Double,lon:Double,function:(String)->Unit) { |
| | | fun getAddress(context: Context, lat: Double, lon: Double, function: (String) -> Unit) { |
| | | var geocoderSearch = GeocodeSearch(context); |
| | | // 第一个参数表示一个Latlng,第二参数表示范围多少米,第三个参数表示是火系坐标系还是GPS原生坐标系 |
| | | var query = RegeocodeQuery(LatLonPoint(lat,lon), 500f,GeocodeSearch.AMAP); |
| | | var query = RegeocodeQuery(LatLonPoint(lat, lon), 500f, GeocodeSearch.AMAP); |
| | | geocoderSearch.getFromLocationAsyn(query); |
| | | geocoderSearch.setOnGeocodeSearchListener(object : GeocodeSearch.OnGeocodeSearchListener { |
| | | override fun onRegeocodeSearched(p0: RegeocodeResult?, p1: Int) { |
| | | p0?.let { |
| | | if (p1 != 1000){ |
| | | if (p1 != 1000) { |
| | | function("") |
| | | }else{ |
| | | } else { |
| | | function(it.regeocodeAddress.adCode) |
| | | } |
| | | } |
| | |
| | | /*** |
| | | * 逆地址编码 |
| | | */ |
| | | fun getAddressReg(context: Context,lat:Double,lon:Double,function:(RegeocodeAddress)->Unit) { |
| | | fun getAddressReg( |
| | | context: Context, |
| | | lat: Double, |
| | | lon: Double, |
| | | function: (RegeocodeAddress) -> Unit |
| | | ) { |
| | | var geocoderSearch = GeocodeSearch(context); |
| | | // 第一个参数表示一个Latlng,第二参数表示范围多少米,第三个参数表示是火系坐标系还是GPS原生坐标系 |
| | | var query = RegeocodeQuery(LatLonPoint(lat,lon), 500f,GeocodeSearch.AMAP); |
| | | var query = RegeocodeQuery(LatLonPoint(lat, lon), 500f, GeocodeSearch.AMAP); |
| | | geocoderSearch.getFromLocationAsyn(query); |
| | | geocoderSearch.setOnGeocodeSearchListener(object : GeocodeSearch.OnGeocodeSearchListener { |
| | | override fun onRegeocodeSearched(p0: RegeocodeResult?, p1: Int) { |
| | | p0?.let { |
| | | if (p1 != 1000){ |
| | | if (p1 != 1000) { |
| | | |
| | | }else{ |
| | | } else { |
| | | function(it.regeocodeAddress) |
| | | } |
| | | } |