添加手动输入定位信息,并且显示位置功能。

This commit is contained in:
ZhanGSKen 2025-03-21 17:03:58 +08:00
parent 1113503a23
commit 5e66647495
10 changed files with 497 additions and 246 deletions

View File

@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #Created by .winboll/winboll_app_build.gradle
#Fri Mar 21 03:15:13 GMT 2025 #Fri Mar 21 09:01:41 GMT 2025
stageCount=0 stageCount=0
libraryProject= libraryProject=
baseVersion=1.0 baseVersion=1.0
publishVersion=1.0.0 publishVersion=1.0.0
buildCount=281 buildCount=355
baseBetaVersion=1.0.1 baseBetaVersion=1.0.1

View File

@ -41,6 +41,7 @@ import java.util.List;
import cc.winboll.studio.positions.activities.AbsActivity; import cc.winboll.studio.positions.activities.AbsActivity;
import android.widget.Toolbar; import android.widget.Toolbar;
import cc.winboll.studio.libappbase.utils.ToastUtils; import cc.winboll.studio.libappbase.utils.ToastUtils;
import androidx.fragment.app.FragmentStatePagerAdapter;
final public class MainActivity extends AbsActivity implements IWinBollActivity, ViewPager.OnPageChangeListener, View.OnClickListener { final public class MainActivity extends AbsActivity implements IWinBollActivity, ViewPager.OnPageChangeListener, View.OnClickListener {
@ -51,7 +52,14 @@ final public class MainActivity extends AbsActivity implements IWinBollActivity,
public static final String ACTION_SOS = "cc.winboll.studio.libappbase.WinBoll.ACTION_SOS"; public static final String ACTION_SOS = "cc.winboll.studio.libappbase.WinBoll.ACTION_SOS";
// 创建Fragment列表和标题列表
List<Fragment> fragmentList = new ArrayList<>();
List<String> tabTitleList = new ArrayList<>();
TXMSFragment mTXMSFragment; TXMSFragment mTXMSFragment;
PositionsFragment mPositionsFragment;
TasksFragment mTasksFragment;
LogFragment mLogFragment;
LogView mLogView; LogView mLogView;
Toolbar mToolbar; Toolbar mToolbar;
CheckBox cbMainService; CheckBox cbMainService;
@ -97,13 +105,13 @@ final public class MainActivity extends AbsActivity implements IWinBollActivity,
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
// 初始化工具栏 // 初始化工具栏
mToolbar = findViewById(R.id.toolbar); // mToolbar = findViewById(R.id.toolbar);
setActionBar(mToolbar); // setActionBar(mToolbar);
// if (isEnableDisplayHomeAsUp()) { //// if (isEnableDisplayHomeAsUp()) {
// // 显示后退按钮 //// // 显示后退按钮
// getSupportActionBar().setDisplayHomeAsUpEnabled(true); //// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// } //// }
getActionBar().setTitle(""); // getActionBar().setTitle("");
// 初始化地图视图 // 初始化地图视图
// 创建Fragment实例 // 创建Fragment实例
@ -117,18 +125,23 @@ final public class MainActivity extends AbsActivity implements IWinBollActivity,
tabLayout = findViewById(R.id.tabLayout); tabLayout = findViewById(R.id.tabLayout);
viewPager = findViewById(R.id.viewPager); viewPager = findViewById(R.id.viewPager);
// 创建Fragment列表和标题列表 mPositionsFragment = new PositionsFragment();
List<Fragment> fragmentList = new ArrayList<>(); fragmentList.add(mPositionsFragment);
List<String> tabTitleList = new ArrayList<>();
fragmentList.add(new PositionsFragment());
fragmentList.add(new TasksFragment());
fragmentList.add(new LogFragment());
tabTitleList.add("位置"); tabTitleList.add("位置");
mTasksFragment = new TasksFragment();
fragmentList.add(mTasksFragment);
tabTitleList.add("任务"); tabTitleList.add("任务");
mLogFragment = new LogFragment();
fragmentList.add(mLogFragment);
tabTitleList.add("日志"); tabTitleList.add("日志");
// 设置ViewPager的适配器 // 设置ViewPager的适配器
MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager(), fragmentList, tabTitleList); MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter); viewPager.setAdapter(adapter);
// 关联TabLayout和ViewPager // 关联TabLayout和ViewPager
@ -137,25 +150,23 @@ final public class MainActivity extends AbsActivity implements IWinBollActivity,
// ViewPager的适配器 // ViewPager的适配器
private class MyPagerAdapter extends FragmentPagerAdapter { public class MyPagerAdapter extends FragmentStatePagerAdapter {
private static final int PAGE_COUNT = 3;
private List<Fragment> fragmentList; public MyPagerAdapter(FragmentManager fm) {
private List<String> tabTitleList; super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
public MyPagerAdapter(FragmentManager fm, List<Fragment> fragmentList, List<String> tabTitleList) {
super(fm);
this.fragmentList = fragmentList;
this.tabTitleList = tabTitleList;
} }
@Override @Override
public Fragment getItem(int position) { public Fragment getItem(int position) {
// 根据position返回不同的Fragment
return fragmentList.get(position); return fragmentList.get(position);
} }
@Override @Override
public int getCount() { public int getCount() {
return fragmentList.size(); // 返回页面总数
return PAGE_COUNT;
} }
@Override @Override
@ -163,6 +174,7 @@ final public class MainActivity extends AbsActivity implements IWinBollActivity,
return tabTitleList.get(position); return tabTitleList.get(position);
} }
} }
//初始化view即显示的图片 //初始化view即显示的图片
// void initViewPager() { // void initViewPager() {
// pagerAdapter = new MyPagerAdapter(getSupportFragmentManager()); // pagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
@ -261,7 +273,8 @@ final public class MainActivity extends AbsActivity implements IWinBollActivity,
@Override @Override
public Toolbar initToolBar() { public Toolbar initToolBar() {
return findViewById(R.id.toolbar); return null;
//return findViewById(R.id.toolbar);
} }
@Override @Override

View File

@ -43,8 +43,8 @@ public class LogFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) { @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_log, container, false); View view = inflater.inflate(R.layout.fragment_log, container, false);
LogView logView = view.findViewById(R.id.logview); // LogView logView = view.findViewById(R.id.logview);
logView.start(); // logView.start();
return view; return view;
} }
} }

View File

@ -11,6 +11,9 @@ import android.location.Location;
import android.location.LocationListener; import android.location.LocationListener;
import android.location.LocationManager; import android.location.LocationManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@ -23,21 +26,32 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.utils.ToastUtils;
import cc.winboll.studio.positions.R; import cc.winboll.studio.positions.R;
import cc.winboll.studio.positions.models.PostionFixModel;
import cc.winboll.studio.positions.utils.LocationFusion; import cc.winboll.studio.positions.utils.LocationFusion;
import cc.winboll.studio.positions.utils.TimeUtils;
import android.widget.EditText;
public class PositionsFragment extends Fragment { public class PositionsFragment extends Fragment {
public static final String TAG = "ContactsFragment"; public static final String TAG = "PositionsFragment";
private static final String ARG_PAGE = "ARG_PAGE"; private static final String ARG_PAGE = "ARG_PAGE";
private int mPage; private int mPage;
private LocationManager locationManager; private LocationManager locationManager;
private TextView tvWifiLocation; static MyHandler _MyHandler;
private TextView tvGPSLocation;
private TextView tvFuseLocation; TextView mtvTXMyLocationInfo;
TextView mtvPhoneMyLocationInfo;
TextView mtvPostionFixModelInfo;
TextView mtvLockPostionInfo;
EditText metLockLatitude;
EditText metLockLongitude;
double latitudeWifiLock; double latitudeWifiLock;
double longitudeWifiLock; double longitudeWifiLock;
@ -46,6 +60,14 @@ public class PositionsFragment extends Fragment {
double latitudeFuseLock; double latitudeFuseLock;
double longitudeFuseLock; double longitudeFuseLock;
PostionFixModel mPostionFixModel;
static Location _LocationTX;
static Location _LocationPhoneGPS;
static Location _LocationPhoneGPSLock;
LocationManager locationManagerPhoneGPS;
volatile static int nFixActivationCountValue = 20;
volatile static int nCurrentFixActivationCountValue = 0;
// public static PositionsFragment newInstance(int page) { // public static PositionsFragment newInstance(int page) {
// Bundle args = new Bundle(); // Bundle args = new Bundle();
@ -69,31 +91,112 @@ public class PositionsFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) { @Nullable Bundle savedInstanceState) {
View viewMain = inflater.inflate(R.layout.fragment_positions, container, false); View viewMain = inflater.inflate(R.layout.fragment_positions, container, false);
nCurrentFixActivationCountValue = 0;
// Toolbar toolbar = viewMain.findViewById(R.id.toolbar); // Toolbar toolbar = viewMain.findViewById(R.id.toolbar);
// getActivity().getMenuInflater().inflate(R.menu.toolbar_positions, toolbar.getMenu()); // getActivity().getMenuInflater().inflate(R.menu.toolbar_positions, toolbar.getMenu());
// //
tvWifiLocation = viewMain.findViewById(R.id.wifi_position_tv); mtvTXMyLocationInfo = viewMain.findViewById(R.id.txmylocationinfo_tv);
tvGPSLocation = viewMain.findViewById(R.id.gps_position_tv); mtvPhoneMyLocationInfo = viewMain.findViewById(R.id.phonemylocationinfo_tv);
tvFuseLocation = viewMain.findViewById(R.id.fuse_position_tv); mtvPostionFixModelInfo = viewMain.findViewById(R.id.postionfixmodelinfo_tv);
mtvLockPostionInfo = viewMain.findViewById(R.id.lockpostioninfo_tv);
metLockLatitude = viewMain.findViewById(R.id.locklatitude_et);
metLockLongitude = viewMain.findViewById(R.id.locklongitude_et);
// tvWifiLocation = viewMain.findViewById(R.id.wifi_position_tv);
// tvGPSLocation = viewMain.findViewById(R.id.gps_position_tv);
// tvFuseLocation = viewMain.findViewById(R.id.fuse_position_tv);
locationManager = (LocationManager) getActivity().getSystemService(getActivity().LOCATION_SERVICE); locationManager = (LocationManager) getActivity().getSystemService(getActivity().LOCATION_SERVICE);
Button btnLockingPosition = viewMain.findViewById(R.id.locking_position_btn); Button btnLockingPosition = viewMain.findViewById(R.id.locking_position_btn);
btnLockingPosition.setOnClickListener(new View.OnClickListener(){ btnLockingPosition.setOnClickListener(new View.OnClickListener(){
@Override @Override
public void onClick(View p1) { public void onClick(View p1) {
TXMSFragment.moveToLocation(latitudeFuseLock, longitudeFuseLock); if (!metLockLatitude.getText().toString().trim().equals("")
&& !metLockLongitude.getText().toString().trim().equals("")) {
_LocationPhoneGPSLock = new Location("User_Defined_GPS");
_LocationPhoneGPSLock.setLatitude(Double.parseDouble(metLockLatitude.getText().toString()));
_LocationPhoneGPSLock.setLongitude(Double.parseDouble(metLockLongitude.getText().toString()));
ToastUtils.show("定位手动设定位置");
} else {
// 用腾讯定位数据与GPS定位数据的数据差修复模型来修复一下GPS定位数据
mPostionFixModel = PostionFixModel.loadPostionFixModel();
Location locationFix = fixGPSLocationFromPostionFixModel(_LocationPhoneGPS);
//_LocationPhoneGPSLock = _LocationTX;
_LocationPhoneGPSLock = locationFix;
ToastUtils.show("定位GPS设定位置");
}
showLockPostionInfo();
//ToastUtils.show(String.format("%s", locationFix.toString()));
TXMSFragment.moveToLocation(_LocationPhoneGPSLock.getLatitude(), _LocationPhoneGPSLock.getLongitude());
} }
}); });
// 请求GPS定位 // 请求GPS定位
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, gpsLocationListener); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, phoneGPSLocationListener);
// 请求基站网络定位 // 请求基站网络定位
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, networkLocationListener); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, networkLocationListener);
_MyHandler = new MyHandler();
//ToastUtils.show("PositionsFragment onCreateView");
showLocationTX();
showLocationPhoneGPS();
showPostionFixModelInfo();
return viewMain; return viewMain;
} }
void showLocationPhoneGPS() {
if (_LocationPhoneGPS != null) {
String szTemp = String.format("\nPhoneGPS MyLocation Info\nLatitude %f\nLongitude %f\nAccuracy %f\n", _LocationPhoneGPS.getLatitude(), _LocationPhoneGPS.getLongitude(), _LocationPhoneGPS.getAccuracy());
mtvPhoneMyLocationInfo.append(szTemp);
LogUtils.d(TAG, szTemp);
}
}
void showPostionFixModelInfo() {
if (mPostionFixModel != null && _LocationTX != null && _LocationPhoneGPS != null) {
String szTemp = String.format("\nFixModel Info\nLatitude TX %f\nLatitude GPS %f\nLatitude Fix %f\nLongitude TX %f\nLongitude GPS %f\nLongitude Fix %f\n\n",
_LocationTX.getLatitude(),
_LocationPhoneGPS.getLatitude(),
mPostionFixModel.getLatitudeFixModel(),
_LocationTX.getLongitude(),
_LocationPhoneGPS.getLongitude(),
mPostionFixModel.getLongitudeFixModel());
mtvPostionFixModelInfo.append(szTemp);
LogUtils.d(TAG, szTemp);
}
}
void showLockPostionInfo() {
if (mPostionFixModel != null && _LocationTX != null && _LocationPhoneGPSLock != null) {
String szTemp = String.format("\n%s\nFixModel Info\nLatitude TX %f\nLatitude GPS %f\nLatitude Fix %f\nLongitude TX %f\nLongitude GPS %f\nLongitude Fix %f\n\n",
TimeUtils.getCurrentTimeString(),
_LocationTX.getLatitude(),
_LocationPhoneGPS.getLatitude(),
mPostionFixModel.getLatitudeFixModel(),
_LocationTX.getLongitude(),
_LocationPhoneGPS.getLongitude(),
mPostionFixModel.getLongitudeFixModel());
mtvLockPostionInfo.append(szTemp);
LogUtils.d(TAG, szTemp);
}
}
void showLocationTX() {
if (_LocationTX != null) {
String szTemp = String.format("TX MyLocation Init Info\nLatitude %f, Longitude %f, Accuracy %f", _LocationTX.getLatitude(), _LocationTX.getLongitude(), _LocationTX.getAccuracy());
mtvTXMyLocationInfo.setText(szTemp);
LogUtils.d(TAG, szTemp);
}
}
@Override @Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.toolbar_positions, menu); inflater.inflate(R.menu.toolbar_positions, menu);
@ -108,7 +211,7 @@ public class PositionsFragment extends Fragment {
ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return; return;
} }
locationManager.removeUpdates(gpsLocationListener); locationManager.removeUpdates(phoneGPSLocationListener);
locationManager.removeUpdates(networkLocationListener); locationManager.removeUpdates(networkLocationListener);
} }
} }
@ -128,7 +231,56 @@ public class PositionsFragment extends Fragment {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
private LocationListener gpsLocationListener = new LocationListener() { void updatePostionFixModel() {
if (_LocationPhoneGPS == null
|| _LocationTX == null) {
return;
}
nCurrentFixActivationCountValue++;
if (nCurrentFixActivationCountValue < nFixActivationCountValue) {
mPostionFixModel = PostionFixModel.loadPostionFixModel();
mPostionFixModel.setLatitudeFixModel(_LocationPhoneGPS.getLatitude() - _LocationTX.getLatitude());
mPostionFixModel.setLongitudeFixModel(_LocationPhoneGPS.getLongitude() - _LocationTX.getLongitude());
// String szTemp = String.format("PostionFixModel Info\nLatitude Fix %f, Longitude Fix %f", mPostionFixModel.getLatitudeFixModel(), mPostionFixModel.getLongitudeFixModel());
// mtvPostionFixModelInfo.setText(szTemp);
// LogUtils.d(TAG, szTemp);
PostionFixModel.savePostionFixModel(mPostionFixModel);
//ToastUtils.show(szTemp);
LogUtils.d(TAG, String.format("updatePostionFixModel() run %d", nCurrentFixActivationCountValue));
showPostionFixModelInfo();
} else {
// 定位修复模型数据定型, GPS定位监听停止
// 在需要停止监听的地方如onPause/onDestroy添加
if (locationManagerPhoneGPS != null) {
// 取消位置更新监听
locationManagerPhoneGPS.removeUpdates(phoneGPSLocationListener);
// 可选停止后释放资源
phoneGPSLocationListener = null;
}
LogUtils.d(TAG, String.format("updatePostionFixModel() stop %d", nCurrentFixActivationCountValue));
}
}
private Location fixGPSLocationFromPostionFixModel(Location location) {
//Location location = locationTX;
Location locationFix = new Location("GPS_Fix_Map_Manual");
// 设置基础坐标
locationFix.setLatitude(location.getLatitude() - mPostionFixModel.getLatitudeFixModel());
locationFix.setLongitude(location.getLongitude() - mPostionFixModel.getLongitudeFixModel());
// 设置必要元数据
location.setTime(System.currentTimeMillis());
location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
location.setAccuracy(5.0f); // 手动点击精度设为5米
return location;
}
private LocationListener phoneGPSLocationListener = new LocationListener() {
@Override @Override
public void onLocationChanged(Location location) { public void onLocationChanged(Location location) {
// 处理GPS定位结果 // 处理GPS定位结果
@ -171,22 +323,32 @@ public class PositionsFragment extends Fragment {
longitudeWifiLock = longitude; longitudeWifiLock = longitude;
// 简单的融合示例这里只是显示最后获取到的位置实际应用中需要更复杂的融合算法 // 简单的融合示例这里只是显示最后获取到的位置实际应用中需要更复杂的融合算法
tvWifiLocation.setText(String.format("Wifi [ Latitude: %f \nLongitude: %f ]", latitudeWifiLock, longitudeWifiLock)); //tvWifiLocation.setText(String.format("Wifi [ Latitude: %f \nLongitude: %f ]", latitudeWifiLock, longitudeWifiLock));
fuseLocationData(); fuseLocationData();
} }
} }
void updateGPSLocation(Location location) { void updateGPSLocation(Location location) {
if (location != null) { if (location != null) {
double latitude = location.getLatitude(); // double latitude = location.getLatitude();
double longitude = location.getLongitude(); // double longitude = location.getLongitude();
//
// latitudeGPSLock = latitude;
// longitudeGPSLock = longitude;
//
// // 简单的融合示例这里只是显示最后获取到的位置实际应用中需要更复杂的融合算法
// tvGPSLocation.setText(String.format("GPS [ Latitude: %f \nLongitude: %f ]", latitudeGPSLock, longitudeGPSLock));
// fuseLocationData();
latitudeGPSLock = latitude; _LocationPhoneGPS = location;
longitudeGPSLock = longitude; // 位置变化时的处理逻辑
// double latitude = location.getLatitude();
// 简单的融合示例这里只是显示最后获取到的位置实际应用中需要更复杂的融合算法 // double longitude = location.getLongitude();
tvGPSLocation.setText(String.format("GPS [ Latitude: %f \nLongitude: %f ]", latitudeGPSLock, longitudeGPSLock)); // String szTemp = String.format("Phone GPS MyLocation Init Info\nLatitude %f, Longitude %f, Accuracy %f", _LocationPhoneGPS.getLatitude(), _LocationPhoneGPS.getLongitude(), _LocationPhoneGPS.getAccuracy());
fuseLocationData(); // mtvPhoneMyLocationInfo.setText(szTemp);
// LogUtils.d(TAG, szTemp);
showLocationPhoneGPS();
updatePostionFixModel();
} }
} }
@ -205,6 +367,32 @@ public class PositionsFragment extends Fragment {
latitudeFuseLock = result[0]; latitudeFuseLock = result[0];
longitudeFuseLock = result[1]; longitudeFuseLock = result[1];
tvFuseLocation.setText(String.format("Fuse [ Latitude: %f \nLongitude: %f ]", latitudeFuseLock, longitudeFuseLock)); //tvFuseLocation.setText(String.format("Fuse [ Latitude: %f \nLongitude: %f ]", latitudeFuseLock, longitudeFuseLock));
}
public static final int INIT_POSITION = 1;
class MyHandler extends Handler {
@Override
public void handleMessage(@NonNull Message msg) {
switch (msg.what) {
case INIT_POSITION:
// 在这里处理接收到消息后的逻辑比如更新 UI
_LocationTX = (Location)msg.obj;
showLocationTX();
break;
default:
break;
}
}
};
public static void sendInitPositioningMessage(Location location) {
if (_MyHandler != null) {
Message message = Message.obtain();
message.what = INIT_POSITION;
message.obj = location;
_MyHandler.sendMessage(message);
}
} }
} }

View File

@ -68,21 +68,16 @@ public class TXMSFragment extends Fragment implements /*EasyPermissions.Permissi
private int mPage; private int mPage;
private TextureMapView mapView; private TextureMapView mapView;
protected TencentMap tencentMap; protected TencentMap tencentMap;
TextView mtvTXMyLocationInfo;
TextView mtvPhoneMyLocationInfo;
TextView mtvPostionFixModelInfo;
private LocationSource.OnLocationChangedListener locationChangedListener; private LocationSource.OnLocationChangedListener locationChangedListener;
private TencentLocationManager mTencentLocationManager; private TencentLocationManager mTencentLocationManager;
private TencentLocationRequest mTencentLocationRequest; private TencentLocationRequest mTencentLocationRequest;
private MyLocationStyle mMyLocationStyle; private MyLocationStyle mMyLocationStyle;
ArrayList<PostionModel> locationPostionModelList; ArrayList<PostionModel> locationPostionModelList;
Location lastLocation; //Location lastLocation;
static TXMSFragment _TXMSFragment; static TXMSFragment _TXMSFragment;
PostionFixModel mPostionFixModel;
Location locationTX;
Location locationPhoneGPS;
LocationManager locationManagerPhoneGPS;
@Nullable @Nullable
@Override @Override
@ -101,9 +96,6 @@ public class TXMSFragment extends Fragment implements /*EasyPermissions.Permissi
//创建tencentMap地图对象可以完成对地图的几乎所有操作 //创建tencentMap地图对象可以完成对地图的几乎所有操作
tencentMap = mapView.getMap(); tencentMap = mapView.getMap();
mtvTXMyLocationInfo = viewRoot.findViewById(R.id.txmylocationinfo_tv);
mtvPhoneMyLocationInfo = viewRoot.findViewById(R.id.phonemylocationinfo_tv);
mtvPostionFixModelInfo = viewRoot.findViewById(R.id.postionfixmodelinfo_tv);
checkLocationPermission(); checkLocationPermission();
@ -189,48 +181,30 @@ public class TXMSFragment extends Fragment implements /*EasyPermissions.Permissi
// } // }
// 手机 GPS 定位信息 // 手机 GPS 定位信息
LocationListener phoneGPSLocationListener = new LocationListener() { // LocationListener phoneGPSLocationListener = new LocationListener() {
@Override // @Override
public void onLocationChanged(Location location) { // public void onLocationChanged(Location location) {
locationPhoneGPS = location; // locationPhoneGPS = location;
// 位置变化时的处理逻辑 // // 位置变化时的处理逻辑
// double latitude = location.getLatitude(); //// double latitude = location.getLatitude();
// double longitude = location.getLongitude(); //// double longitude = location.getLongitude();
String szTemp = String.format("Phone GPS MyLocation Init Info\nLatitude %f, Longitude %f, Accuracy %f", locationPhoneGPS.getLatitude(), locationPhoneGPS.getLongitude(), locationPhoneGPS.getAccuracy()); // String szTemp = String.format("Phone GPS MyLocation Init Info\nLatitude %f, Longitude %f, Accuracy %f", locationPhoneGPS.getLatitude(), locationPhoneGPS.getLongitude(), locationPhoneGPS.getAccuracy());
mtvPhoneMyLocationInfo.setText(szTemp); // mtvPhoneMyLocationInfo.setText(szTemp);
LogUtils.d(TAG, szTemp); // LogUtils.d(TAG, szTemp);
updatePostionFixModel(); // updatePostionFixModel();
// }
//
// @Override
// public void onProviderDisabled(String provider) {}
//
// @Override
// public void onProviderEnabled(String provider) {}
//
// @Override
// public void onStatusChanged(String provider, int status, Bundle extras) {}
// };
}
@Override
public void onProviderDisabled(String provider) {}
@Override
public void onProviderEnabled(String provider) {}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
};
void updatePostionFixModel() {
mPostionFixModel = PostionFixModel.loadPostionFixModel();
mPostionFixModel.setLatitudeFixModel(locationPhoneGPS.getLatitude() - locationTX.getLatitude());
mPostionFixModel.setLongitudeFixModel(locationPhoneGPS.getLongitude() - locationTX.getLongitude());
PostionFixModel.savePostionFixModel(mPostionFixModel);
String szTemp = String.format("PostionFixModel Info\nLatitude Fix %f, Longitude Fix %f", mPostionFixModel.getLatitudeFixModel(), mPostionFixModel.getLongitudeFixModel());
mtvPostionFixModelInfo.setText(szTemp);
LogUtils.d(TAG, szTemp);
// 在需要停止监听的地方如onPause/onDestroy添加
if (locationManagerPhoneGPS != null) {
// 取消位置更新监听
locationManagerPhoneGPS.removeUpdates(phoneGPSLocationListener);
// 可选停止后释放资源
phoneGPSLocationListener = null;
}
}
// 创建Location对象方法 // 创建Location对象方法
@ -375,32 +349,14 @@ public class TXMSFragment extends Fragment implements /*EasyPermissions.Permissi
} }
} }
private Location fixGPSLocationFromPostionFixModel(Location location) {
Location locationFix = new Location("GPS_Fix_Map_Manual");
// 设置基础坐标
locationFix.setLatitude(location.getLatitude() - mPostionFixModel.getLatitudeFixModel());
locationFix.setLongitude(location.getLongitude() - mPostionFixModel.getLongitudeFixModel());
// 设置必要元数据
location.setTime(System.currentTimeMillis());
location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
location.setAccuracy(5.0f); // 手动点击精度设为5米
return location;
}
private void moveToGPSLocation(Location location) { private void moveToGPSLocation(Location location) {
// 用腾讯定位数据与GPS定位数据的数据差修复模型来修复一下GPS定位数据
mPostionFixModel = PostionFixModel.loadPostionFixModel();
Location locationFix = fixGPSLocationFromPostionFixModel(location);
//ToastUtils.show(String.format("%s", locationFix.toString()));
//对地图操作类进行操作 //对地图操作类进行操作
CameraUpdate cameraSigma = CameraUpdate cameraSigma =
CameraUpdateFactory.newCameraPosition(new CameraPosition( CameraUpdateFactory.newCameraPosition(new CameraPosition(
convertLocationToLatLng(locationFix), convertLocationToLatLng(location),
15, 19f,
0f, 0f,
0f)); 0f));
//移动地图 //移动地图
@ -427,7 +383,7 @@ public class TXMSFragment extends Fragment implements /*EasyPermissions.Permissi
public void onLocationChanged(TencentLocation tencentLocation, int i, String s) { public void onLocationChanged(TencentLocation tencentLocation, int i, String s) {
if (i == TencentLocation.ERROR_OK && locationChangedListener != null) { if (i == TencentLocation.ERROR_OK && locationChangedListener != null) {
locationTX = new Location(tencentLocation.getProvider()); final Location locationTX = new Location(tencentLocation.getProvider());
//设置经纬度以及精度 //设置经纬度以及精度
locationTX.setLatitude(tencentLocation.getLatitude()); locationTX.setLatitude(tencentLocation.getLatitude());
locationTX.setLongitude(tencentLocation.getLongitude()); locationTX.setLongitude(tencentLocation.getLongitude());
@ -436,48 +392,50 @@ public class TXMSFragment extends Fragment implements /*EasyPermissions.Permissi
locationChangedListener.onLocationChanged(locationTX); locationChangedListener.onLocationChanged(locationTX);
//显示回调的实时位置信息 //显示回调的实时位置信息
getActivity().runOnUiThread(new Runnable() { // getActivity().runOnUiThread(new Runnable() {
@Override // @Override
public void run() { // public void run() {
//
//对地图操作类进行操作 // //对地图操作类进行操作
// CameraUpdate cameraSigma = //// CameraUpdate cameraSigma =
// CameraUpdateFactory.newCameraPosition(new CameraPosition( //// CameraUpdateFactory.newCameraPosition(new CameraPosition(
// convertToLatLng(location), //// convertToLatLng(location),
// 15, //// 15,
// 0f, //// 0f,
// 0f)); //// 0f));
// //移动地图 //// //移动地图
// tencentMap.moveCamera(cameraSigma); //// tencentMap.moveCamera(cameraSigma);
// Rules.getEffectInfo(location); //// Rules.getEffectInfo(location);
// double distance = DistanceUtils.getDistance( //// double distance = DistanceUtils.getDistance(
// locationA.getLatitude(), //// locationA.getLatitude(),
// locationA.getLongitude(), //// locationA.getLongitude(),
// locationB.getLatitude(), //// locationB.getLatitude(),
// locationB.getLongitude() //// locationB.getLongitude()
// ); //// );
String szTemp = String.format("TX MyLocation Init Info\nLatitude %f, Longitude %f, Accuracy %f", locationTX.getLatitude(), locationTX.getLongitude(), locationTX.getAccuracy()); // String szTemp = String.format("TX MyLocation Init Info\nLatitude %f, Longitude %f, Accuracy %f", locationTX.getLatitude(), locationTX.getLongitude(), locationTX.getAccuracy());
mtvTXMyLocationInfo.setText(szTemp); // mtvTXMyLocationInfo.setText(szTemp);
LogUtils.d(TAG, szTemp); // LogUtils.d(TAG, szTemp);
//打印tencentLocation的json字符串 // //打印tencentLocation的json字符串
// Toast.makeText(getApplicationContext(), new Gson().toJson(location), Toast.LENGTH_LONG).show(); //// Toast.makeText(getApplicationContext(), new Gson().toJson(location), Toast.LENGTH_LONG).show();
//
//
// // //
// 本机 GPS 定位服务调用服务 // // 本机 GPS 定位服务调用服务
// // //
locationManagerPhoneGPS = (LocationManager) getActivity().getSystemService(getActivity().LOCATION_SERVICE); // locationManagerPhoneGPS = (LocationManager) getActivity().getSystemService(getActivity().LOCATION_SERVICE);
String provider = LocationManager.GPS_PROVIDER; // String provider = LocationManager.GPS_PROVIDER;
//Location location = locationManager.getLastKnownLocation(provider); // //Location location = locationManager.getLastKnownLocation(provider);
locationManagerPhoneGPS.requestLocationUpdates(provider, 2000, 10, phoneGPSLocationListener); // locationManagerPhoneGPS.requestLocationUpdates(provider, 2000, 10, phoneGPSLocationListener);
} // }
}); // });
// 保存最后定位信息 // 保存最后定位信息
lastLocation = new Location(tencentLocation.getProvider()); // lastLocation = new Location(tencentLocation.getProvider());
lastLocation.setLatitude(tencentLocation.getLatitude()); // lastLocation.setLatitude(tencentLocation.getLatitude());
lastLocation.setLongitude(tencentLocation.getLongitude()); // lastLocation.setLongitude(tencentLocation.getLongitude());
lastLocation.setAccuracy(tencentLocation.getAccuracy()); // lastLocation.setAccuracy(tencentLocation.getAccuracy());
PositionsFragment.sendInitPositioningMessage(locationTX);
// 当不再需要定位时 // 当不再需要定位时
// 取消定位监听 // 取消定位监听
@ -488,6 +446,8 @@ public class TXMSFragment extends Fragment implements /*EasyPermissions.Permissi
if (tencentMap != null) { if (tencentMap != null) {
tencentMap.setMyLocationEnabled(false); tencentMap.setMyLocationEnabled(false);
} }
} }
} }

View File

@ -21,7 +21,7 @@ import cc.winboll.studio.libappbase.utils.ToastUtils;
public class TasksFragment extends Fragment { public class TasksFragment extends Fragment {
public static final String TAG = "GmsFragment"; public static final String TAG = "TasksFragment";
private static final String ARG_PAGE = "ARG_PAGE"; private static final String ARG_PAGE = "ARG_PAGE";
private int mPage; private int mPage;

View File

@ -0,0 +1,26 @@
package cc.winboll.studio.positions.utils;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/03/21 16:02:56
* @Describe 时间工具集
*/
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class TimeUtils {
public static final String TAG = "TimeUtils";
public static String getCurrentTimeString() {
// 获取当前日期时间
LocalDateTime now = LocalDateTime.now();
// 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 格式化日期时间
String formattedDateTime = now.format(formatter);
//System.out.println(formattedDateTime);
return formattedDateTime;
}
}

View File

@ -9,14 +9,9 @@
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="400dp" android:layout_height="300dp"
android:id="@+id/frameLayout"/> android:id="@+id/frameLayout"/>
<android.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar"/>
<androidx.viewpager.widget.ViewPager <androidx.viewpager.widget.ViewPager
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"

View File

@ -7,40 +7,158 @@
android:layout_height="match_parent"> android:layout_height="match_parent">
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="0dp"
android:gravity="center_vertical"
android:layout_weight="1.0"> android:layout_weight="1.0">
<LinearLayout <TextView
android:orientation="vertical" android:id="@+id/txmylocationinfo_tv"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1.0"> android:textColor="@color/colorPrimary"
android:textStyle="bold"
android:textSize="10sp"
android:background="#C0FFFFFF">
<TextView </TextView>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/wifi_position_tv"/>
<TextView <LinearLayout
android:layout_width="match_parent" android:orientation="horizontal"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:id="@+id/gps_position_tv"/> android:layout_height="wrap_content">
<TextView <LinearLayout
android:layout_width="match_parent" android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/fuse_position_tv"/> android:layout_weight="1.0">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFC4EF9E">
<TextView
android:id="@+id/phonemylocationinfo_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:textStyle="bold"
android:textSize="10sp">
</TextView>
</ScrollView>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFABE2F7">
<TextView
android:id="@+id/postionfixmodelinfo_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:textStyle="bold"
android:textSize="10sp">
</TextView>
</ScrollView>
</LinearLayout>
</LinearLayout> </LinearLayout>
<Button </LinearLayout>
android:layout_width="wrap_content"
android:layout_height="wrap_content" <LinearLayout
android:text="定位" android:orientation="horizontal"
android:id="@+id/locking_position_btn"/> android:layout_width="match_parent"
android:layout_height="150dp">
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:background="#FFADA4FD">
<TextView
android:id="@+id/lockpostioninfo_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:textStyle="bold"
android:textSize="10sp">
</TextView>
</ScrollView>
<LinearLayout
android:orientation="vertical"
android:layout_width="150dp"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Latitude:"/>
<EditText
android:layout_width="0dp"
android:ems="10"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:id="@+id/locklatitude_et"
android:singleLine="true"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Longitude:"/>
<EditText
android:layout_width="0dp"
android:ems="10"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:id="@+id/locklongitude_et"
android:singleLine="true"/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="定位"
android:id="@+id/locking_position_btn"/>
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -5,62 +5,13 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:background="#FFF4E3FF">
<RelativeLayout <com.tencent.tencentmap.mapsdk.maps.TextureMapView
android:id="@+id/mapview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"/>
<com.tencent.tencentmap.mapsdk.maps.TextureMapView
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txmylocationinfo_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:textStyle="bold"
android:textSize="10sp"
android:background="#C0FFFFFF">
</TextView>
<TextView
android:id="@+id/phonemylocationinfo_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:textStyle="bold"
android:textSize="10sp"
android:background="#C0FFFFFF"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true">
</TextView>
<TextView
android:id="@+id/postionfixmodelinfo_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:textStyle="bold"
android:textSize="10sp"
android:background="#C0FFFFFF"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true">
</TextView>
</LinearLayout>
</RelativeLayout>
</LinearLayout> </LinearLayout>