| | |
| | | |
| | | |
| | | import java.io.File; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | |
| | | * 获取位置信息,包括经纬度 |
| | | */ |
| | | private void uniGetLocationInfo(String type, Object data, DCUniMPJSCallback callback) { |
| | | |
| | | |
| | | try { |
| | | // 初始化LocationManager对象 |
| | | LocationManager locationManager = (LocationManager) HDLApp.getInstance().getSystemService(Context.LOCATION_SERVICE); |
| | | Geolocation geolocation = new Geolocation(); |
| | |
| | | Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); |
| | | if (location == null) { |
| | | geolocation.setResult(-3); |
| | | geolocation.setDes(HDLApp.getInstance().getString(R.string.exception_the_location_function_is_not_enabled)); |
| | | geolocation.setDes(HDLApp.getInstance().getString(R.string.exception_unable_location_move10_meters_later)); |
| | | uniCallbackData(type, geolocation, callback); |
| | | return; |
| | | } |
| | | geolocation.setResult(0); |
| | | geolocation.setDes(HDLApp.getInstance().getString(R.string.succeed)); |
| | | geolocation.setLongitude(location.getLatitude());//纬度 |
| | | geolocation.setLatitude(location.getLongitude());//经度 |
| | | BigDecimal latitude = BigDecimal.valueOf(location.getLatitude());//经度 |
| | | BigDecimal longitude = BigDecimal.valueOf(location.getLongitude());//纬度 |
| | | double lat = latitude.setScale(6, RoundingMode.HALF_DOWN).doubleValue(); |
| | | double lon = longitude.setScale(6, RoundingMode.HALF_DOWN).doubleValue(); |
| | | geolocation.setLatitude(lat);//经度 |
| | | geolocation.setLongitude(lon);//纬度 |
| | | uniCallbackData(type, geolocation, callback); |
| | | HdlLogLogic.print("经纬度--->经度:" + location.getLongitude() + "纬度:" + location.getLatitude(), true); |
| | | |
| | | } catch (Exception e) { |
| | | Geolocation geolocation = new Geolocation(); |
| | | geolocation.setResult(-4); |
| | | geolocation.setDes(e.getMessage()); |
| | | uniCallbackData(type, geolocation, callback); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | callback.invoke(getJSONObject(uniCallBackBaseBean)); |
| | | // callback.invoke(uniCallBackBaseBean); |
| | | HdlLogLogic.print("uni--->接收--->" + type + "--->" + new Gson().toJson(uniCallBackBaseBean), true); |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | HdlLogLogic.print("uni--->接收--->" + type + "--->" + e.getMessage(), false); |
| | | HdlLogLogic.print("uni--->接收--->" + type + "--->" + e.getMessage(), true); |
| | | } |
| | | |
| | | |