# PdGPS **Repository Path**: lishashalss/pd-gps ## Basic Information - **Project Name**: PdGPS - **Description**: gps+网络融合的后台实时定位,增加单次定位类 - **Primary Language**: Android - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2025-09-09 - **Last Updated**: 2025-09-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # PdGPS #### 介绍 gps+网络融合的后台实时定位,增加单次定位类 #### 软件架构 gps+network融合定位,最大可能的提升手机定位精度,里面也包含有单次定位工具类和电池优化设置跳转工具类(处理不同厂商系统的电池优化设置页面跳转) #### 安装教程 ``` implementation 'com.gitee.gzlpsdp:pd-gps:1.1' ``` #### 使用说明 1. 为保障后台定位实时运行,需要获取定位权限并打开精确位置及位置权限最好设置为始终允许、处理电池优化。 2. 不需要实时返回定位信息也可以使用单次定位工具进行定位。 3. 使用电池优化工具类进行电池优化。 #### 使用 1.使用持续定位,需要获取定位权限并打开精确位置及位置权限最好设置为始终允许,否则可能判断精度不过无法返回定位信息 ``` //引入数据接收模型 private LocationViewModel locationViewModel; //在方法中使用 // 初始化ViewModel locationViewModel = new ViewModelProvider(this).get(LocationViewModel.class); // 观察位置更新 locationViewModel.getData().observe(this, new Observer() { @Override public void onChanged(LocationPoint locationPoint) { System.out.println("返回的定位信息:" + locationPoint); } }); //启动定位服务 locationViewModel.startTrackingService(this); //关闭定位服务 locationViewModel.stopTrackingService(this); private boolean isLocationServiceRunning() { // 此处简化实现,实际应检查服务是否在运行 return locationViewModel.isTrackingServiceRunning(TrackingService.class, this); } ``` 2.使用单次定位 ``` // 使用自定义单次定位请求器 SingleLocationRequester requester = new SingleLocationRequester(this); requester.requestLocation(new SingleLocationRequester.SingleLocationCallback() { @Override public void onLocationReceived(Location location) { runOnUiThread(() -> { // 显示位置信息 Toast.makeText(MainActivity.this, "定位成功" + location.getLongitude() + "," + location.getLatitude(), Toast.LENGTH_SHORT).show(); }); } @Override public void onLocationFailed(String errorMessage) { runOnUiThread(() -> { Toast.makeText(MainActivity.this, "定位失败: " + errorMessage, Toast.LENGTH_SHORT).show(); }); } }); ```