Commit 0bad6b91faa605479e3db8ea9ce8ab585e7e9e5e
1 parent
f478a583
1.赛事详情
Showing
6 changed files
with
285 additions
and
17 deletions
library_baidumap/src/main/AndroidManifest.xml
| 1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 3 | + xmlns:tools="http://schemas.android.com/tools" | ||
| 3 | package="com.example.moudle_baidumap"> | 4 | package="com.example.moudle_baidumap"> |
| 4 | 5 | ||
| 5 | <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" /> | 6 | <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" /> |
| @@ -19,6 +20,16 @@ | @@ -19,6 +20,16 @@ | ||
| 19 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | 20 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> |
| 20 | <!-- 访问网络,网络定位需要上网 --> | 21 | <!-- 访问网络,网络定位需要上网 --> |
| 21 | <uses-permission android:name="android.permission.INTERNET" /> | 22 | <uses-permission android:name="android.permission.INTERNET" /> |
| 23 | + <!-- 这个权限用于获取wifi的获取权限,wifi信息会用来进行网络定位--> | ||
| 24 | + <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission> | ||
| 25 | + <!-- SD卡读取权限,用于写入对象存储BOS数据--> | ||
| 26 | + <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" | ||
| 27 | + tools:ignore="ProtectedPermissions"></uses-permission> | ||
| 28 | + <!-- 用于加快GPS首次定位--> | ||
| 29 | + <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission> | ||
| 30 | + <!-- 用于Android M及以上系统,申请加入忽略电池优化白名单--> | ||
| 31 | + <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"></uses-permission> | ||
| 32 | + | ||
| 22 | <application> | 33 | <application> |
| 23 | <service | 34 | <service |
| 24 | android:name="com.baidu.location.f" | 35 | android:name="com.baidu.location.f" |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/presenter/RunningMapFragmentPresenter.java
| @@ -8,10 +8,23 @@ import android.widget.Toast; | @@ -8,10 +8,23 @@ import android.widget.Toast; | ||
| 8 | 8 | ||
| 9 | import com.baidu.mapapi.map.BitmapDescriptorFactory; | 9 | import com.baidu.mapapi.map.BitmapDescriptorFactory; |
| 10 | import com.baidu.mapapi.map.MarkerOptions; | 10 | import com.baidu.mapapi.map.MarkerOptions; |
| 11 | +import com.baidu.mapapi.map.Overlay; | ||
| 11 | import com.baidu.mapapi.map.OverlayOptions; | 12 | import com.baidu.mapapi.map.OverlayOptions; |
| 12 | import com.baidu.mapapi.model.LatLng; | 13 | import com.baidu.mapapi.model.LatLng; |
| 14 | +import com.baidu.trace.api.entity.AddEntityResponse; | ||
| 15 | +import com.baidu.trace.api.entity.AroundSearchResponse; | ||
| 16 | +import com.baidu.trace.api.entity.BoundSearchResponse; | ||
| 17 | +import com.baidu.trace.api.entity.DeleteEntityResponse; | ||
| 18 | +import com.baidu.trace.api.entity.DistrictSearchResponse; | ||
| 19 | +import com.baidu.trace.api.entity.EntityInfo; | ||
| 20 | +import com.baidu.trace.api.entity.EntityListRequest; | ||
| 13 | import com.baidu.trace.api.entity.EntityListResponse; | 21 | import com.baidu.trace.api.entity.EntityListResponse; |
| 22 | +import com.baidu.trace.api.entity.FilterCondition; | ||
| 23 | +import com.baidu.trace.api.entity.LocRequest; | ||
| 14 | import com.baidu.trace.api.entity.OnEntityListener; | 24 | import com.baidu.trace.api.entity.OnEntityListener; |
| 25 | +import com.baidu.trace.api.entity.PolygonSearchResponse; | ||
| 26 | +import com.baidu.trace.api.entity.SearchResponse; | ||
| 27 | +import com.baidu.trace.api.entity.SortBy; | ||
| 15 | import com.baidu.trace.api.entity.UpdateEntityResponse; | 28 | import com.baidu.trace.api.entity.UpdateEntityResponse; |
| 16 | import com.baidu.trace.api.track.HistoryTrackRequest; | 29 | import com.baidu.trace.api.track.HistoryTrackRequest; |
| 17 | import com.baidu.trace.api.track.HistoryTrackResponse; | 30 | import com.baidu.trace.api.track.HistoryTrackResponse; |
| @@ -45,14 +58,23 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag | @@ -45,14 +58,23 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag | ||
| 45 | private int pageSize = 1000; | 58 | private int pageSize = 1000; |
| 46 | //分页索引 | 59 | //分页索引 |
| 47 | private int pageIndex = 1; | 60 | private int pageIndex = 1; |
| 61 | + //分页大小 | ||
| 62 | + private int realTimePageSize = 1000; | ||
| 63 | + //分页索引 | ||
| 64 | + private int realTimePageIndex = 1; | ||
| 48 | /** | 65 | /** |
| 49 | * 历史轨迹请求 | 66 | * 历史轨迹请求 |
| 50 | */ | 67 | */ |
| 51 | private HistoryTrackRequest historyTrackRequest; | 68 | private HistoryTrackRequest historyTrackRequest; |
| 52 | /** | 69 | /** |
| 70 | + * 实时轨迹请求 | ||
| 71 | + */ | ||
| 72 | + private LocRequest realTimeListRequest; | ||
| 73 | + /** | ||
| 53 | * 轨迹点集合 | 74 | * 轨迹点集合 |
| 54 | */ | 75 | */ |
| 55 | private List<LatLng> trackPoints; | 76 | private List<LatLng> trackPoints; |
| 77 | + private List<LatLng> realTimePoints; | ||
| 56 | 78 | ||
| 57 | /** | 79 | /** |
| 58 | * 查询历史轨迹 | 80 | * 查询历史轨迹 |
| @@ -86,11 +108,11 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag | @@ -86,11 +108,11 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag | ||
| 86 | //绑路:设置是否将轨迹点绑定至路网道路 | 108 | //绑路:设置是否将轨迹点绑定至路网道路 |
| 87 | processOption.setNeedMapMatch(false); | 109 | processOption.setNeedMapMatch(false); |
| 88 | //抽稀:设置是否进行抽稀处理,对冗余的轨迹点进行抽稀去除处理,如一条直线上除起终点外的多个轨迹点 | 110 | //抽稀:设置是否进行抽稀处理,对冗余的轨迹点进行抽稀去除处理,如一条直线上除起终点外的多个轨迹点 |
| 89 | - processOption.setNeedVacuate(true); | 111 | +// processOption.setNeedVacuate(true); |
| 90 | //自动判断交通方式 | 112 | //自动判断交通方式 |
| 91 | processOption.setTransportMode(TransportMode.walking); | 113 | processOption.setTransportMode(TransportMode.walking); |
| 92 | // 设置精度过滤值(定位精度大于100米的过滤掉) | 114 | // 设置精度过滤值(定位精度大于100米的过滤掉) |
| 93 | - processOption.setRadiusThreshold(20); | 115 | + processOption.setRadiusThreshold(9); |
| 94 | // 设置纠偏选项 | 116 | // 设置纠偏选项 |
| 95 | historyTrackRequest.setProcessOption(processOption); | 117 | historyTrackRequest.setProcessOption(processOption); |
| 96 | // 设置里程填充方式为驾车 | 118 | // 设置里程填充方式为驾车 |
| @@ -159,4 +181,98 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag | @@ -159,4 +181,98 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag | ||
| 159 | 181 | ||
| 160 | } | 182 | } |
| 161 | 183 | ||
| 184 | + | ||
| 185 | + public void queryRealTimeTrace(Context context, String entityName, long activeTime) { | ||
| 186 | + if (realTimeListRequest == null) { | ||
| 187 | + List<String> names = new ArrayList<>(); | ||
| 188 | + names.add(entityName); | ||
| 189 | + realTimeListRequest = new LocRequest(); | ||
| 190 | + realTimeListRequest.setServiceId(StepService.serviceId); | ||
| 191 | + realTimeListRequest.setTag(1); | ||
| 192 | + } | ||
| 193 | + if (realTimePoints == null) { | ||
| 194 | + realTimePoints = new ArrayList<>(); | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + OnEntityListener onEntityListener = new OnEntityListener() { | ||
| 198 | + Overlay realTimeOverlay = null; | ||
| 199 | + | ||
| 200 | + @Override | ||
| 201 | + public void onEntityListCallback(EntityListResponse entityListResponse) { | ||
| 202 | + super.onEntityListCallback(entityListResponse); | ||
| 203 | + Log.e(TAG, "onEntityListCallback"); | ||
| 204 | + Toast.makeText(context, "onEntityListCallback", Toast.LENGTH_SHORT).show(); | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + @Override | ||
| 208 | + public void onSearchEntityCallback(SearchResponse searchResponse) { | ||
| 209 | + super.onSearchEntityCallback(searchResponse); | ||
| 210 | + Log.e(TAG, "onSearchEntityCallback"); | ||
| 211 | + Toast.makeText(context, "onSearchEntityCallback", Toast.LENGTH_SHORT).show(); | ||
| 212 | + | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + @Override | ||
| 216 | + public void onBoundSearchCallback(BoundSearchResponse boundSearchResponse) { | ||
| 217 | + super.onBoundSearchCallback(boundSearchResponse); | ||
| 218 | + Log.e(TAG, "onBoundSearchCallback"); | ||
| 219 | + Toast.makeText(context, "onBoundSearchCallback", Toast.LENGTH_SHORT).show(); | ||
| 220 | + | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + @Override | ||
| 224 | + public void onAroundSearchCallback(AroundSearchResponse aroundSearchResponse) { | ||
| 225 | + super.onAroundSearchCallback(aroundSearchResponse); | ||
| 226 | + Log.e(TAG, "onAroundSearchCallback"); | ||
| 227 | + Toast.makeText(context, "onAroundSearchCallback", Toast.LENGTH_SHORT).show(); | ||
| 228 | + | ||
| 229 | + } | ||
| 230 | + | ||
| 231 | + @Override | ||
| 232 | + public void onPolygonSearchCallback(PolygonSearchResponse polygonSearchResponse) { | ||
| 233 | + super.onPolygonSearchCallback(polygonSearchResponse); | ||
| 234 | + Log.e(TAG, "onPolygonSearchCallback"); | ||
| 235 | + Toast.makeText(context, "onPolygonSearchCallback", Toast.LENGTH_SHORT).show(); | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + @Override | ||
| 239 | + public void onDistrictSearchCallback(DistrictSearchResponse districtSearchResponse) { | ||
| 240 | + super.onDistrictSearchCallback(districtSearchResponse); | ||
| 241 | + Log.e(TAG, "onDistrictSearchCallback"); | ||
| 242 | + Toast.makeText(context, "onDistrictSearchCallback", Toast.LENGTH_SHORT).show(); | ||
| 243 | + | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + /**实时定位回调接口 | ||
| 247 | + * @param traceLocation | ||
| 248 | + */ | ||
| 249 | + @Override | ||
| 250 | + public void onReceiveLocation(TraceLocation traceLocation) { | ||
| 251 | + super.onReceiveLocation(traceLocation); | ||
| 252 | + Log.e(TAG, "onReceiveLocation"); | ||
| 253 | + Toast.makeText(context, "onReceiveLocation", Toast.LENGTH_SHORT).show(); | ||
| 254 | + | ||
| 255 | + Log.e(TAG, "onReceiveLocation"); | ||
| 256 | + if (traceLocation != null) { | ||
| 257 | + realTimePoints.add(new LatLng(traceLocation.getLatitude(), traceLocation.getLongitude())); | ||
| 258 | + } | ||
| 259 | + if (realTimePoints.size() > 2) { | ||
| 260 | + if (getView() != null) { | ||
| 261 | + if (realTimeOverlay == null) { | ||
| 262 | + realTimeOverlay = MyMapUtil.drawMapLine(context, getView().baiduMap, realTimePoints, R.color.black); | ||
| 263 | + } else { | ||
| 264 | + realTimeOverlay.remove(); | ||
| 265 | + realTimeOverlay = MyMapUtil.drawMapLine(context, getView().baiduMap, realTimePoints, R.color.black); | ||
| 266 | + | ||
| 267 | + } | ||
| 268 | + } | ||
| 269 | + } | ||
| 270 | + } | ||
| 271 | + }; | ||
| 272 | + //查询实时轨迹 | ||
| 273 | + if (StepService.mClient != null) { | ||
| 274 | + StepService.mClient.queryRealTimeLoc(realTimeListRequest, onEntityListener); | ||
| 275 | + } | ||
| 276 | + | ||
| 277 | + } | ||
| 162 | } | 278 | } |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunningMapFragmentView.java
| @@ -80,7 +80,7 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { | @@ -80,7 +80,7 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { | ||
| 80 | mUiSettings = baiduMap.getUiSettings(); | 80 | mUiSettings = baiduMap.getUiSettings(); |
| 81 | } | 81 | } |
| 82 | //设置定位模式, 默认为 LocationMode.NORMAL 普通态 | 82 | //设置定位模式, 默认为 LocationMode.NORMAL 普通态 |
| 83 | - mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL; | 83 | + mCurrentMode = MyLocationConfiguration.LocationMode.FOLLOWING; |
| 84 | // 设置定位图标修改为自定义marker | 84 | // 设置定位图标修改为自定义marker |
| 85 | Bitmap pointBitmap = BitmapUtil.getBitmapFromDp(getContext(), BitmapFactory.decodeResource(getContext().getResources(), R.drawable.rt_ic_location), 40, 40); | 85 | Bitmap pointBitmap = BitmapUtil.getBitmapFromDp(getContext(), BitmapFactory.decodeResource(getContext().getResources(), R.drawable.rt_ic_location), 40, 40); |
| 86 | mCurrentMarker = BitmapDescriptorFactory.fromBitmap(pointBitmap); | 86 | mCurrentMarker = BitmapDescriptorFactory.fromBitmap(pointBitmap); |
| @@ -173,7 +173,7 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { | @@ -173,7 +173,7 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { | ||
| 173 | mylocation = new MyLocationData.Builder() | 173 | mylocation = new MyLocationData.Builder() |
| 174 | .accuracy(location.getRadius()) | 174 | .accuracy(location.getRadius()) |
| 175 | // 此处设置开发者获取到的方向信息,顺时针0-360 | 175 | // 此处设置开发者获取到的方向信息,顺时针0-360 |
| 176 | - .direction(location.getDirection()).latitude(location.getLatitude()) | 176 | + .direction(mCurrentDirection).latitude(location.getLatitude()) |
| 177 | .longitude(location.getLongitude()).build(); | 177 | .longitude(location.getLongitude()).build(); |
| 178 | if (mylocation == null) { | 178 | if (mylocation == null) { |
| 179 | return; | 179 | return; |
| @@ -181,20 +181,27 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { | @@ -181,20 +181,27 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { | ||
| 181 | 181 | ||
| 182 | MapStatus.Builder builder = new MapStatus.Builder(); | 182 | MapStatus.Builder builder = new MapStatus.Builder(); |
| 183 | 183 | ||
| 184 | - if (isFirstLoc) { | ||
| 185 | - isFirstLoc = false; | ||
| 186 | - firstLatLng = new LatLng(location.getLatitude(), | ||
| 187 | - location.getLongitude()); | ||
| 188 | - baiduMap.setMyLocationData(mylocation); | ||
| 189 | - builder.target(firstLatLng).zoom(DEFULT_ZOOM); | ||
| 190 | - baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); | 184 | +// if (isFirstLoc) { |
| 185 | +// isFirstLoc = false; | ||
| 186 | + firstLatLng = new LatLng(location.getLatitude(), | ||
| 187 | + location.getLongitude()); | ||
| 188 | + baiduMap.setMyLocationData(mylocation); | ||
| 189 | +// if (isFirstLoc) { | ||
| 190 | +// builder.target(firstLatLng).zoom(DEFULT_ZOOM); | ||
| 191 | +// isFirstLoc = false; | ||
| 192 | +// } else { | ||
| 193 | +// float current = baiduMap.getMapStatus().zoom; | ||
| 194 | +// builder.target(firstLatLng).zoom(current); | ||
| 195 | +// | ||
| 196 | +// } | ||
| 197 | +// baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); | ||
| 191 | // //显示当前位置图标 | 198 | // //显示当前位置图标 |
| 192 | // Bitmap pointBitmap = BitmapUtil.getBitmapFromDp(getContext(), BitmapFactory.decodeResource(getContext().getResources(), R.drawable.rt_ic_location), 40, 40); | 199 | // Bitmap pointBitmap = BitmapUtil.getBitmapFromDp(getContext(), BitmapFactory.decodeResource(getContext().getResources(), R.drawable.rt_ic_location), 40, 40); |
| 193 | // currentMark = new MarkerOptions().position(firstLatLng).icon(BitmapDescriptorFactory.fromBitmap(pointBitmap)); | 200 | // currentMark = new MarkerOptions().position(firstLatLng).icon(BitmapDescriptorFactory.fromBitmap(pointBitmap)); |
| 194 | // baiduMap.addOverlay(currentMark); | 201 | // baiduMap.addOverlay(currentMark); |
| 195 | 202 | ||
| 196 | 203 | ||
| 197 | - } | 204 | +// } |
| 198 | } | 205 | } |
| 199 | } | 206 | } |
| 200 | 207 | ||
| @@ -267,12 +274,12 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { | @@ -267,12 +274,12 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { | ||
| 267 | double x = sensorEvent.values[SensorManager.DATA_X]; | 274 | double x = sensorEvent.values[SensorManager.DATA_X]; |
| 268 | if (Math.abs(x - lastX) > 1.0) { | 275 | if (Math.abs(x - lastX) > 1.0) { |
| 269 | mCurrentDirection = (int) x; | 276 | mCurrentDirection = (int) x; |
| 270 | - if (firstLatLng != null) { | 277 | + if (mylocation != null) { |
| 271 | mylocation = new MyLocationData.Builder() | 278 | mylocation = new MyLocationData.Builder() |
| 272 | .accuracy(mCurrentAccracy) | 279 | .accuracy(mCurrentAccracy) |
| 273 | // 此处设置开发者获取到的方向信息,顺时针0-360 | 280 | // 此处设置开发者获取到的方向信息,顺时针0-360 |
| 274 | - .direction(mCurrentDirection).latitude(firstLatLng.latitude) | ||
| 275 | - .longitude(firstLatLng.longitude).build(); | 281 | + .direction(mCurrentDirection).latitude(mylocation.latitude) |
| 282 | + .longitude(mylocation.longitude).build(); | ||
| 276 | baiduMap.setMyLocationData(mylocation); | 283 | baiduMap.setMyLocationData(mylocation); |
| 277 | } | 284 | } |
| 278 | } | 285 | } |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/service/StepService.java
| @@ -142,9 +142,9 @@ public class StepService extends Service implements SensorEventListener { | @@ -142,9 +142,9 @@ public class StepService extends Service implements SensorEventListener { | ||
| 142 | */ | 142 | */ |
| 143 | private OnTrackListener realTimeTraceListener = null; | 143 | private OnTrackListener realTimeTraceListener = null; |
| 144 | //位置采集周期 | 144 | //位置采集周期 |
| 145 | - private int gatherInterval = 5; | 145 | + private int gatherInterval = 3; |
| 146 | //打包周期 | 146 | //打包周期 |
| 147 | - private int packInterval = 30; | 147 | + private int packInterval = 10; |
| 148 | // 轨迹服务ID | 148 | // 轨迹服务ID |
| 149 | // public static final long serviceId = 213511; | 149 | // public static final long serviceId = 213511; |
| 150 | //杨帅 | 150 | //杨帅 |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/fragment/RunningMapFragment.java
| @@ -102,6 +102,8 @@ public class RunningMapFragment extends QMUIFragment<RunningMapFragmentView, Run | @@ -102,6 +102,8 @@ public class RunningMapFragment extends QMUIFragment<RunningMapFragmentView, Run | ||
| 102 | long endTime = current; | 102 | long endTime = current; |
| 103 | // Log.e(TAG, "onViewCreated: " + "hour:" + hour + ",minute" + minute + ",second:" + second); | 103 | // Log.e(TAG, "onViewCreated: " + "hour:" + hour + ",minute" + minute + ",second:" + second); |
| 104 | getPresenter().queryHistoryTrace(getActivity(), StepService.entityName, startTime, endTime); | 104 | getPresenter().queryHistoryTrace(getActivity(), StepService.entityName, startTime, endTime); |
| 105 | + //查询实时轨迹 | ||
| 106 | + getPresenter().queryRealTimeTrace(getActivity(),StepService.entityName, startTime); | ||
| 105 | } | 107 | } |
| 106 | } | 108 | } |
| 107 | 109 |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/MyMapUtil.java
| @@ -78,4 +78,136 @@ public class MyMapUtil { | @@ -78,4 +78,136 @@ public class MyMapUtil { | ||
| 78 | baiduMap.addOverlay(endOptions); | 78 | baiduMap.addOverlay(endOptions); |
| 79 | return baiduMap.addOverlay(polylineOptions); | 79 | return baiduMap.addOverlay(polylineOptions); |
| 80 | } | 80 | } |
| 81 | + | ||
| 82 | + | ||
| 83 | + public static Overlay drawMapLine(Context context, BaiduMap baiduMap, List<LatLng> points, int lineColor) { | ||
| 84 | + OverlayOptions polylineOptions = new PolylineOptions().width(10) | ||
| 85 | + .color(context.getResources().getColor(lineColor)).points(points); | ||
| 86 | + return baiduMap.addOverlay(polylineOptions); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + public static double pi = 3.1415926535897932384626; | ||
| 90 | + public static double a = 6378245.0; | ||
| 91 | + public static double ee = 0.00669342162296594323; | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * 将GCJ-02(谷歌地图坐标)转换成BD-09(百度地图坐标) | ||
| 95 | + */ | ||
| 96 | + public static LatLng gcj02_To_Bd09(double gg_lat, double gg_lon) { | ||
| 97 | + double x = gg_lon, y = gg_lat; | ||
| 98 | + double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * pi); | ||
| 99 | + double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * pi); | ||
| 100 | + double bd_lon = z * Math.cos(theta) + 0.0065; | ||
| 101 | + double bd_lat = z * Math.sin(theta) + 0.006; | ||
| 102 | + return new LatLng(bd_lat, bd_lon); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + public static LatLng wgs84_To_Bd09(double gg_lat, double gg_lon) { | ||
| 106 | + LatLng latLng = wgs84togcj02(gg_lat, gg_lon); | ||
| 107 | + return gcj02_To_Bd09(latLng.latitude, latLng.longitude); | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * WGS84转GCj02 | ||
| 112 | + * | ||
| 113 | + * @param lng | ||
| 114 | + * @param lat | ||
| 115 | + * @returns {*[]} | ||
| 116 | + */ | ||
| 117 | + public static LatLng wgs84togcj02(double lat, double lng) { | ||
| 118 | + double dlat = transformlat(lng - 105.0, lat - 35.0); | ||
| 119 | + double dlng = transformlng(lng - 105.0, lat - 35.0); | ||
| 120 | + double radlat = lat / 180.0 * pi; | ||
| 121 | + double magic = Math.sin(radlat); | ||
| 122 | + magic = 1 - ee * magic * magic; | ||
| 123 | + double sqrtmagic = Math.sqrt(magic); | ||
| 124 | + dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi); | ||
| 125 | + dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * pi); | ||
| 126 | + double mglat = lat + dlat; | ||
| 127 | + double mglng = lng + dlng; | ||
| 128 | + return new LatLng(mglat, mglng); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + private static double transformlat(double lng, double lat) { | ||
| 132 | + double ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng)); | ||
| 133 | + ret += (20.0 * Math.sin(6.0 * lng * pi) + 20.0 * Math.sin(2.0 * lng * pi)) * 2.0 / 3.0; | ||
| 134 | + ret += (20.0 * Math.sin(lat * pi) + 40.0 * Math.sin(lat / 3.0 * pi)) * 2.0 / 3.0; | ||
| 135 | + ret += (160.0 * Math.sin(lat / 12.0 * pi) + 320 * Math.sin(lat * pi / 30.0)) * 2.0 / 3.0; | ||
| 136 | + return ret; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + private static double transformlng(double lng, double lat) { | ||
| 140 | + double ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng)); | ||
| 141 | + ret += (20.0 * Math.sin(6.0 * lng * pi) + 20.0 * Math.sin(2.0 * lng * pi)) * 2.0 / 3.0; | ||
| 142 | + ret += (20.0 * Math.sin(lng * pi) + 40.0 * Math.sin(lng / 3.0 * pi)) * 2.0 / 3.0; | ||
| 143 | + ret += (150.0 * Math.sin(lng / 12.0 * pi) + 300.0 * Math.sin(lng / 30.0 * pi)) * 2.0 / 3.0; | ||
| 144 | + return ret; | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | +// /** | ||
| 148 | +// * 根据经纬极值计算绽放级别 | ||
| 149 | +// */ | ||
| 150 | +// public static float getZoom(List<LatLng> points) { | ||
| 151 | +// double maxLng = points.get(points.size() - 1).longitude; | ||
| 152 | +// double minLng = points.get(0).longitude; | ||
| 153 | +// double maxLat = points.get(points.size() - 1).latitude; | ||
| 154 | +// double minLat = points.get(0).latitude; | ||
| 155 | +// LatLng tempLatLng; | ||
| 156 | +// | ||
| 157 | +// | ||
| 158 | +// for (LatLng latLng : points) { | ||
| 159 | +// tempLatLng = latLng; | ||
| 160 | +// if (tempLatLng.longitude > maxLng) maxLng = tempLatLng.longitude; | ||
| 161 | +// if (tempLatLng.longitude < minLng) minLng = tempLatLng.longitude; | ||
| 162 | +// if (tempLatLng.latitude > maxLat) maxLat = tempLatLng.latitude; | ||
| 163 | +// if (tempLatLng.latitude < minLat) minLat = tempLatLng.latitude; | ||
| 164 | +// } | ||
| 165 | +// | ||
| 166 | +// double[] zooms = {50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 25000, 50000, 100000, 200000, 500000, 1000000, 2000000};//级别18到3。 | ||
| 167 | +// LatLng pointA = new LatLng(maxLat, maxLng); // 创建点坐标A | ||
| 168 | +// LatLng pointB = new LatLng(minLat, minLng); // 创建点坐标B | ||
| 169 | +//// double distance = DistanceUtil.getDistance(pointA, pointB); //获取两点距离,保留小数点后两位 | ||
| 170 | +// for (int i = 0, zoomLen = zooms.length; i < zoomLen; i++) { | ||
| 171 | +// if (zooms[i] - distance > 0) { | ||
| 172 | +// return 18 - i + 3;//之所以会多3,是因为地图范围常常是比例尺距离的10倍以上。所以级别会增加3。 | ||
| 173 | +// } | ||
| 174 | +// } | ||
| 175 | +// return 18; | ||
| 176 | +// } | ||
| 177 | + | ||
| 178 | + /** | ||
| 179 | + * 获取经纬度中心点 | ||
| 180 | + * | ||
| 181 | + * @param points | ||
| 182 | + * @return | ||
| 183 | + */ | ||
| 184 | + public static LatLng getCenterZoomPosition(List<LatLng> points) { | ||
| 185 | + double maxLng = points.get(points.size() - 1).longitude; | ||
| 186 | + double minLng = points.get(0).longitude; | ||
| 187 | + double maxLat = points.get(points.size() - 1).latitude; | ||
| 188 | + double minLat = points.get(0).latitude; | ||
| 189 | + double cenLng = (maxLng + minLng) / 2; | ||
| 190 | + double cenLat = (maxLat + minLat) / 2; | ||
| 191 | + return new LatLng(cenLat, cenLng); | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + | ||
| 195 | + /** | ||
| 196 | + * 经纬度是否为(0,0)点 | ||
| 197 | + * | ||
| 198 | + * @return | ||
| 199 | + */ | ||
| 200 | + public static boolean isZeroPoint(double latitude, double longitude) { | ||
| 201 | + return isEqualToZero(latitude) && isEqualToZero(longitude); | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + /** | ||
| 205 | + * 校验double数值是否为0 | ||
| 206 | + * | ||
| 207 | + * @param value | ||
| 208 | + * @return | ||
| 209 | + */ | ||
| 210 | + public static boolean isEqualToZero(double value) { | ||
| 211 | + return Math.abs(value - 0.0) < 0.01 ? true : false; | ||
| 212 | + } | ||
| 81 | } | 213 | } |