Commit d6bd0614f859beed136e3c0f6d88d1b87a554e2b
1 parent
5e1ebd76
1 优化GPS开启判断方式
Showing
1 changed file
with
14 additions
and
11 deletions
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/MyMapUtil.java
| ... | ... | @@ -217,18 +217,18 @@ public class MyMapUtil { |
| 217 | 217 | int index = 0; |
| 218 | 218 | boolean isContinue = false; |
| 219 | 219 | for (int i = 0; i < importPoints.size(); i++) { |
| 220 | - isContinue=false; | |
| 220 | + isContinue = false; | |
| 221 | 221 | LatLng importLatLng = importPoints.get(i); |
| 222 | 222 | for (int j = index; j < trackPoints.size(); j++) { |
| 223 | 223 | double distance = DistanceUtil.getDistance(importLatLng, trackPoints.get(j)); |
| 224 | 224 | if (distance < Constant.CHECK_ACCURACY) { |
| 225 | 225 | importHash.put(i, true); |
| 226 | 226 | index = j; |
| 227 | - isContinue=true; | |
| 227 | + isContinue = true; | |
| 228 | 228 | break; |
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | - if (isContinue){ | |
| 231 | + if (isContinue) { | |
| 232 | 232 | continue; |
| 233 | 233 | } |
| 234 | 234 | } |
| ... | ... | @@ -376,16 +376,19 @@ public class MyMapUtil { |
| 376 | 376 | * @return true 表示开启 |
| 377 | 377 | */ |
| 378 | 378 | public static final boolean isOPenGps(final Context context) { |
| 379 | - LocationManager locationManager | |
| 380 | - = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); | |
| 381 | - // 通过GPS卫星定位,定位级别可以精确到街(通过24颗卫星定位,在室外和空旷的地方定位准确、速度快) | |
| 382 | - boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); | |
| 383 | - // 通过WLAN或移动网络(3G/2G)确定的位置(也称作AGPS,辅助GPS定位。主要用于在室内或遮盖物(建筑群或茂密的深林等)密集的地方定位) | |
| 384 | - boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); | |
| 385 | - if (gps) { | |
| 379 | + try { | |
| 380 | + LocationManager locationManager | |
| 381 | + = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); | |
| 382 | + // 通过GPS卫星定位,定位级别可以精确到街(通过24颗卫星定位,在室外和空旷的地方定位准确、速度快) | |
| 383 | + boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); | |
| 384 | + // 通过WLAN或移动网络(3G/2G)确定的位置(也称作AGPS,辅助GPS定位。主要用于在室内或遮盖物(建筑群或茂密的深林等)密集的地方定位) | |
| 385 | + boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); | |
| 386 | + if (gps) { | |
| 387 | + return true; | |
| 388 | + } | |
| 389 | + } catch (Exception e) { | |
| 386 | 390 | return true; |
| 387 | 391 | } |
| 388 | - | |
| 389 | 392 | return false; |
| 390 | 393 | } |
| 391 | 394 | ... | ... |