From 44ba605a4e850efa757020da5fb4cf02bdf6e3ab Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期一, 08 九月 2025 10:55:18 +0800
Subject: [PATCH] 2025年09月08日10:55:15
---
app/src/main/java/com/hdl/photovoltaic/utils/GPSManagerUtils.java | 35 +++++++++++++++++++++++++++++++----
1 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/app/src/main/java/com/hdl/photovoltaic/utils/GPSManagerUtils.java b/app/src/main/java/com/hdl/photovoltaic/utils/GPSManagerUtils.java
index 2276c15..6dfb8cc 100644
--- a/app/src/main/java/com/hdl/photovoltaic/utils/GPSManagerUtils.java
+++ b/app/src/main/java/com/hdl/photovoltaic/utils/GPSManagerUtils.java
@@ -4,16 +4,21 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.location.Address;
+import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
+import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
+import java.util.Locale;
+import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import com.hdl.photovoltaic.other.HdlLogLogic;
@@ -33,6 +38,27 @@
public static GPSManagerUtils getInstance() {
return Singleton.INSTANCE;
+ }
+
+ public String getCountryCode(Context context) throws IOException {
+ LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
+ if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+ // 澶勭悊鏉冮檺璇锋眰
+ return null;
+ }
+ Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+ if (location == null) {
+ location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
+ }
+ if (location != null) {
+ Geocoder geocoder = new Geocoder(context, Locale.getDefault());
+ List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
+ if (addresses != null && !addresses.isEmpty()) {
+ return addresses.get(0).getCountryCode();
+ }
+ }
+
+ return null;
}
/**
@@ -66,7 +92,8 @@
showLocation(location);
} else {
// 鐩戣鍦扮悊浣嶇疆鍙樺寲锛岀浜屼釜鍜岀涓変釜鍙傛暟鍒嗗埆涓烘洿鏂扮殑鏈�鐭椂闂磎inTime鍜屾渶鐭窛绂籱inDistace
- locationManager.requestLocationUpdates(locationProvider, 60 * 1000, 10, mListener);
+ //60绉掓洿鐪佺數
+ locationManager.requestLocationUpdates(locationProvider, 30 * 1000, 10, mListener);
}
}
@@ -81,8 +108,8 @@
BigDecimal latitude = BigDecimal.valueOf(location.getLatitude());
String lon = longitude.setScale(6, RoundingMode.HALF_DOWN).doubleValue() + "";
String lat = latitude.setScale(6, RoundingMode.HALF_DOWN).doubleValue() + "";
-// HdlLogLogic.print("绾害--->" + lon, false);
-// HdlLogLogic.print("缁忓害--->" + lat, false);
+ HdlLogLogic.print("绾害--->" + lon, false);
+ HdlLogLogic.print("缁忓害--->" + lat, false);
// if(!TextUtils.isEmpty(lon)&&!TextUtils.isEmpty(lat)){
// DataController.getInstance().lonLatUpdate(lon,lat,new IResponseCallBack<String>() {
// @Override
@@ -113,7 +140,7 @@
// 濡傛灉浣嶇疆鍙戠敓鍙樺寲锛岄噸鏂版樉绀�
@Override
- public void onLocationChanged(Location location) {
+ public void onLocationChanged(@NonNull Location location) {
showLocation(location);
}
};
--
Gitblit v1.8.0