更新定位服务数据请求结构
This commit is contained in:
parent
58ae10f93d
commit
d025fb4f13
@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Thu Apr 03 03:19:30 GMT 2025
|
#Thu Apr 03 06:08:46 GMT 2025
|
||||||
stageCount=0
|
stageCount=0
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=1.0
|
baseVersion=1.0
|
||||||
publishVersion=1.0.0
|
publishVersion=1.0.0
|
||||||
buildCount=375
|
buildCount=382
|
||||||
baseBetaVersion=1.0.1
|
baseBetaVersion=1.0.1
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
<!-- 只能在前台获取精确的位置信息 -->
|
<!-- 只能在前台获取精确的位置信息 -->
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||||
|
|
||||||
<!-- 只能在前台获取大概位置(基于网络) -->
|
<!-- 只有在前台运行时才能获取大致位置信息 -->
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||||
|
|
||||||
<!-- 连接WLAN网络和断开连接 -->
|
<!-- 连接WLAN网络和断开连接 -->
|
||||||
@ -739,6 +739,8 @@
|
|||||||
|
|
||||||
<activity android:name="cc.winboll.studio.positions.activities.JointPositioningActivity"/>
|
<activity android:name="cc.winboll.studio.positions.activities.JointPositioningActivity"/>
|
||||||
|
|
||||||
|
<service android:name="cc.winboll.studio.positions.services.GPSService"/>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -36,6 +36,8 @@ import cc.winboll.studio.positions.models.MainServiceBean;
|
|||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import cc.winboll.studio.positions.listeners.OnTXRTLocationListener;
|
||||||
|
import android.location.Location;
|
||||||
|
|
||||||
final public class MainActivity extends AbsActivity implements IWinBollActivity, ViewPager.OnPageChangeListener, View.OnClickListener {
|
final public class MainActivity extends AbsActivity implements IWinBollActivity, ViewPager.OnPageChangeListener, View.OnClickListener {
|
||||||
|
|
||||||
@ -112,7 +114,7 @@ final public class MainActivity extends AbsActivity implements IWinBollActivity,
|
|||||||
fragmentList.add(mLogFragment);
|
fragmentList.add(mLogFragment);
|
||||||
tabTitleList.add("日志");
|
tabTitleList.add("日志");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 设置ViewPager的适配器
|
// 设置ViewPager的适配器
|
||||||
MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager());
|
MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager());
|
||||||
@ -120,6 +122,13 @@ final public class MainActivity extends AbsActivity implements IWinBollActivity,
|
|||||||
|
|
||||||
// 关联TabLayout和ViewPager
|
// 关联TabLayout和ViewPager
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
tabLayout.setupWithViewPager(viewPager);
|
||||||
|
|
||||||
|
mTXMSFragment.setOnTXRTLocationListener(new OnTXRTLocationListener(){
|
||||||
|
@Override
|
||||||
|
public void onTXRTLocation(Location location) {
|
||||||
|
mPositionsFragment.showLocationTX(location);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,6 +34,13 @@ import cc.winboll.studio.positions.utils.LocationFusion;
|
|||||||
import cc.winboll.studio.positions.utils.TimeUtils;
|
import cc.winboll.studio.positions.utils.TimeUtils;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
|
import android.content.Intent;
|
||||||
|
import cc.winboll.studio.positions.services.GPSService;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.ServiceConnection;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import cc.winboll.studio.positions.listeners.OnGPSRTLocationListener;
|
||||||
|
|
||||||
public class PositionsFragment extends Fragment {
|
public class PositionsFragment extends Fragment {
|
||||||
|
|
||||||
@ -44,10 +51,13 @@ public class PositionsFragment extends Fragment {
|
|||||||
|
|
||||||
private LocationManager locationManager;
|
private LocationManager locationManager;
|
||||||
|
|
||||||
static MyHandler _MyHandler;
|
//MyHandler mMyHandler;
|
||||||
|
|
||||||
TextView mtvTXMyLocationInfo;
|
TextView mtvTXMyLocationInfo;
|
||||||
TextView mtvPhoneMyLocationInfo;
|
TextView mtvPhoneGPSInfo;
|
||||||
|
MyServiceConnection mMyServiceConnection;
|
||||||
|
GPSService mGPSService;
|
||||||
|
|
||||||
TextView mtvPostionFixModelInfo;
|
TextView mtvPostionFixModelInfo;
|
||||||
TextView mtvLockPostionInfo;
|
TextView mtvLockPostionInfo;
|
||||||
|
|
||||||
@ -64,8 +74,8 @@ public class PositionsFragment extends Fragment {
|
|||||||
double longitudeFuseLock;
|
double longitudeFuseLock;
|
||||||
|
|
||||||
PostionFixModel mPostionFixModel;
|
PostionFixModel mPostionFixModel;
|
||||||
static Location _LocationTX;
|
Location mLocationTX;
|
||||||
static Location _LocationPhoneGPS;
|
Location mLocationPhoneGPS;
|
||||||
static Location _LocationPhoneGPSLock;
|
static Location _LocationPhoneGPSLock;
|
||||||
|
|
||||||
LocationManager locationManagerPhoneGPS;
|
LocationManager locationManagerPhoneGPS;
|
||||||
@ -95,29 +105,33 @@ 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;
|
|
||||||
nGPSUpdateCount = 0;
|
|
||||||
|
|
||||||
// Toolbar toolbar = viewMain.findViewById(R.id.toolbar);
|
|
||||||
// getActivity().getMenuInflater().inflate(R.menu.toolbar_positions, toolbar.getMenu());
|
|
||||||
//
|
|
||||||
mtvTXMyLocationInfo = viewMain.findViewById(R.id.txmylocationinfo_tv);
|
mtvTXMyLocationInfo = viewMain.findViewById(R.id.txmylocationinfo_tv);
|
||||||
mtvPhoneMyLocationInfo = viewMain.findViewById(R.id.phonemylocationinfo_tv);
|
mtvPhoneGPSInfo = viewMain.findViewById(R.id.phonegpsinfo_tv);
|
||||||
mtvPostionFixModelInfo = viewMain.findViewById(R.id.postionfixmodelinfo_tv);
|
mMyServiceConnection = new MyServiceConnection();
|
||||||
mtvLockPostionInfo = viewMain.findViewById(R.id.lockpostioninfo_tv);
|
|
||||||
|
Intent intent = new Intent(getActivity(), GPSService.class);
|
||||||
|
getActivity().startService(intent);
|
||||||
|
getActivity().bindService(intent, mMyServiceConnection, Context.BIND_IMPORTANT);
|
||||||
|
|
||||||
|
// metLockLatitude = viewMain.findViewById(R.id.locklatitude_et);
|
||||||
|
// metLockLongitude = viewMain.findViewById(R.id.locklongitude_et);
|
||||||
|
// metLockLatitude.setEnabled(false);
|
||||||
|
// metLockLongitude.setEnabled(false);
|
||||||
|
// mswTaskService = viewMain.findViewById(R.id.taskservice_sw);
|
||||||
|
|
||||||
|
//mMyHandler = new MyHandler();
|
||||||
|
|
||||||
|
//nCurrentFixActivationCountValue = 0;
|
||||||
|
//nGPSUpdateCount = 0;
|
||||||
|
|
||||||
metLockLatitude = viewMain.findViewById(R.id.locklatitude_et);
|
|
||||||
metLockLongitude = viewMain.findViewById(R.id.locklongitude_et);
|
// mtvPostionFixModelInfo = viewMain.findViewById(R.id.postionfixmodelinfo_tv);
|
||||||
metLockLatitude.setEnabled(false);
|
// mtvLockPostionInfo = viewMain.findViewById(R.id.lockpostioninfo_tv);
|
||||||
metLockLongitude.setEnabled(false);
|
//
|
||||||
|
|
||||||
|
//locationManager = (LocationManager) getActivity().getSystemService(getActivity().LOCATION_SERVICE);
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
mswTaskService = viewMain.findViewById(R.id.taskservice_sw);
|
|
||||||
// mswTaskService.setOnClickListener(new View.OnClickListener(){
|
// mswTaskService.setOnClickListener(new View.OnClickListener(){
|
||||||
// @Override
|
// @Override
|
||||||
// public void onClick(View p1) {
|
// public void onClick(View p1) {
|
||||||
@ -126,18 +140,18 @@ public class PositionsFragment extends Fragment {
|
|||||||
// });
|
// });
|
||||||
|
|
||||||
// 请求GPS定位
|
// 请求GPS定位
|
||||||
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, phoneGPSLocationListener);
|
//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");
|
//ToastUtils.show("PositionsFragment onCreateView");
|
||||||
|
|
||||||
showLocationTX();
|
//showLocationTX();
|
||||||
showLocationPhoneGPS();
|
//showLocationPhoneGPS();
|
||||||
showPostionFixModelInfo();
|
//showPostionFixModelInfo();
|
||||||
|
|
||||||
|
|
||||||
return viewMain;
|
return viewMain;
|
||||||
}
|
}
|
||||||
@ -150,64 +164,83 @@ public class PositionsFragment extends Fragment {
|
|||||||
_LocationPhoneGPSLock.setLongitude(Double.parseDouble(metLockLongitude.getText().toString()));
|
_LocationPhoneGPSLock.setLongitude(Double.parseDouble(metLockLongitude.getText().toString()));
|
||||||
//ToastUtils.show("定位手动设定位置");
|
//ToastUtils.show("定位手动设定位置");
|
||||||
} else {
|
} else {
|
||||||
Location locationFix = fixGPSLocationFromPostionFixModel(_LocationPhoneGPS);
|
//Location locationFix = fixGPSLocationFromPostionFixModel(_LocationPhoneGPS);
|
||||||
//_LocationPhoneGPSLock = _LocationTX;
|
//_LocationPhoneGPSLock = _LocationTX;
|
||||||
_LocationPhoneGPSLock = locationFix;
|
//_LocationPhoneGPSLock = locationFix;
|
||||||
//ToastUtils.show("定位GPS设定位置");
|
//ToastUtils.show("定位GPS设定位置");
|
||||||
}
|
}
|
||||||
showLockPostionInfo();
|
//showLockPostionInfo();
|
||||||
//ToastUtils.show(String.format("%s", locationFix.toString()));
|
//ToastUtils.show(String.format("%s", locationFix.toString()));
|
||||||
|
|
||||||
TXMSFragment.moveToLocation(_LocationPhoneGPSLock.getLatitude(), _LocationPhoneGPSLock.getLongitude());
|
TXMSFragment.moveToLocation(_LocationPhoneGPSLock.getLatitude(), _LocationPhoneGPSLock.getLongitude());
|
||||||
}
|
}
|
||||||
|
|
||||||
void showLocationPhoneGPS() {
|
// void showLocationPhoneGPS(Location location) {
|
||||||
if (_LocationPhoneGPS != null) {
|
// if (location != null) {
|
||||||
String szTemp = String.format("\n(%d)PhoneGPS MyLocation Info\nLatitude %f\nLongitude %f\nAccuracy %f\n", nGPSUpdateCount, _LocationPhoneGPS.getLatitude(), _LocationPhoneGPS.getLongitude(), _LocationPhoneGPS.getAccuracy());
|
// mLocationPhoneGPS = location;
|
||||||
mtvPhoneMyLocationInfo.append(szTemp);
|
// String szTemp = String.format("\n(%d)PhoneGPS MyLocation Info\nLatitude %f\nLongitude %f\nAccuracy %f\n", nGPSUpdateCount, _LocationPhoneGPS.getLatitude(), _LocationPhoneGPS.getLongitude(), _LocationPhoneGPS.getAccuracy());
|
||||||
LogUtils.d(TAG, szTemp);
|
// mtvPhoneMyLocationInfo.append(szTemp);
|
||||||
}
|
// LogUtils.d(TAG, szTemp);
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
void showPostionFixModelInfo() {
|
// void showPostionFixModelInfo() {
|
||||||
if (mPostionFixModel != null && _LocationTX != null && _LocationPhoneGPS != null) {
|
// if (mPostionFixModel != null && mLocationTX != null && _LocationPhoneGPS != null) {
|
||||||
String szTemp = String.format("\n(%d)FixModel Info\nLatitude TX %f\nLatitude GPS %f\nLatitude Fix %f\nLongitude TX %f\nLongitude GPS %f\nLongitude Fix %f\n\n",
|
// String szTemp = String.format("\n(%d)FixModel Info\nLatitude TX %f\nLatitude GPS %f\nLatitude Fix %f\nLongitude TX %f\nLongitude GPS %f\nLongitude Fix %f\n\n",
|
||||||
nCurrentFixActivationCountValue,
|
// nCurrentFixActivationCountValue,
|
||||||
_LocationTX.getLatitude(),
|
// mLocationTX.getLatitude(),
|
||||||
_LocationPhoneGPS.getLatitude(),
|
// _LocationPhoneGPS.getLatitude(),
|
||||||
mPostionFixModel.getLatitudeFixModel(),
|
// mPostionFixModel.getLatitudeFixModel(),
|
||||||
_LocationTX.getLongitude(),
|
// mLocationTX.getLongitude(),
|
||||||
_LocationPhoneGPS.getLongitude(),
|
// _LocationPhoneGPS.getLongitude(),
|
||||||
mPostionFixModel.getLongitudeFixModel());
|
// mPostionFixModel.getLongitudeFixModel());
|
||||||
mtvPostionFixModelInfo.append(szTemp);
|
// mtvPostionFixModelInfo.append(szTemp);
|
||||||
LogUtils.d(TAG, szTemp);
|
// LogUtils.d(TAG, szTemp);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
void showLockPostionInfo() {
|
// void showLockPostionInfo() {
|
||||||
if (mPostionFixModel != null && _LocationTX != null && _LocationPhoneGPSLock != null) {
|
// if (mPostionFixModel != null && mLocationTX != null && _LocationPhoneGPSLock != null) {
|
||||||
String szTemp = String.format("\n%s\nFixModel Info\nLatitude TX %f\nLatitude GPS %f\nLatitude Fix %f\nLatitude GPSLock %f\nLongitude TX %f\nLongitude GPS %f\nLongitude Fix %f\nLongitude GPSLock %f\n\n",
|
// String szTemp = String.format("\n%s\nFixModel Info\nLatitude TX %f\nLatitude GPS %f\nLatitude Fix %f\nLatitude GPSLock %f\nLongitude TX %f\nLongitude GPS %f\nLongitude Fix %f\nLongitude GPSLock %f\n\n",
|
||||||
TimeUtils.getCurrentTimeString(),
|
// TimeUtils.getCurrentTimeString(),
|
||||||
_LocationTX.getLatitude(),
|
// mLocationTX.getLatitude(),
|
||||||
_LocationPhoneGPS.getLatitude(),
|
// _LocationPhoneGPS.getLatitude(),
|
||||||
mPostionFixModel.getLatitudeFixModel(),
|
// mPostionFixModel.getLatitudeFixModel(),
|
||||||
_LocationPhoneGPSLock.getLatitude(),
|
// _LocationPhoneGPSLock.getLatitude(),
|
||||||
_LocationTX.getLongitude(),
|
// mLocationTX.getLongitude(),
|
||||||
_LocationPhoneGPS.getLongitude(),
|
// _LocationPhoneGPS.getLongitude(),
|
||||||
mPostionFixModel.getLongitudeFixModel(),
|
// mPostionFixModel.getLongitudeFixModel(),
|
||||||
_LocationPhoneGPSLock.getLongitude());
|
// _LocationPhoneGPSLock.getLongitude());
|
||||||
mtvLockPostionInfo.append(szTemp);
|
// mtvLockPostionInfo.append(szTemp);
|
||||||
LogUtils.d(TAG, szTemp);
|
// LogUtils.d(TAG, szTemp);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
void showLocationTX() {
|
// void showLocationTX() {
|
||||||
if (_LocationTX != null) {
|
// if (_LocationTX != null) {
|
||||||
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);
|
||||||
|
// LogUtils.d(TAG, szTemp);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
public void showLocationTX(Location location) {
|
||||||
|
if (location != null) {
|
||||||
|
mLocationTX = location;
|
||||||
|
String szTemp = String.format("TX MyLocation Info\nLatitude %f, Longitude %f\nAccuracy %f", mLocationTX.getLatitude(), mLocationTX.getLongitude(), mLocationTX.getAccuracy());
|
||||||
mtvTXMyLocationInfo.setText(szTemp);
|
mtvTXMyLocationInfo.setText(szTemp);
|
||||||
LogUtils.d(TAG, szTemp);
|
LogUtils.d(TAG, szTemp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void showLocationPhoneGPS(Location location) {
|
||||||
|
if (location != null) {
|
||||||
|
mLocationPhoneGPS = location;
|
||||||
|
String szTemp = String.format("Phone GPS Info\nLatitude %f, Longitude %f\nAccuracy %f", mLocationPhoneGPS.getLatitude(), mLocationPhoneGPS.getLongitude(), mLocationPhoneGPS.getAccuracy());
|
||||||
|
mtvPhoneGPSInfo.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) {
|
||||||
@ -243,38 +276,38 @@ public class PositionsFragment extends Fragment {
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void updatePostionFixModel() {
|
// void updatePostionFixModel() {
|
||||||
if (_LocationPhoneGPS == null
|
// if (_LocationPhoneGPS == null
|
||||||
|| _LocationTX == null) {
|
// || mLocationTX == null) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
nCurrentFixActivationCountValue++;
|
// nCurrentFixActivationCountValue++;
|
||||||
if (nCurrentFixActivationCountValue < nFixActivationCountValue) {
|
// if (nCurrentFixActivationCountValue < nFixActivationCountValue) {
|
||||||
mPostionFixModel = PostionFixModel.loadPostionFixModel();
|
// mPostionFixModel = PostionFixModel.loadPostionFixModel();
|
||||||
mPostionFixModel.setLatitudeFixModel(_LocationPhoneGPS.getLatitude() - _LocationTX.getLatitude());
|
// mPostionFixModel.setLatitudeFixModel(_LocationPhoneGPS.getLatitude() - mLocationTX.getLatitude());
|
||||||
mPostionFixModel.setLongitudeFixModel(_LocationPhoneGPS.getLongitude() - _LocationTX.getLongitude());
|
// mPostionFixModel.setLongitudeFixModel(_LocationPhoneGPS.getLongitude() - mLocationTX.getLongitude());
|
||||||
|
//
|
||||||
// String szTemp = String.format("PostionFixModel Info\nLatitude Fix %f, Longitude Fix %f", mPostionFixModel.getLatitudeFixModel(), mPostionFixModel.getLongitudeFixModel());
|
//// String szTemp = String.format("PostionFixModel Info\nLatitude Fix %f, Longitude Fix %f", mPostionFixModel.getLatitudeFixModel(), mPostionFixModel.getLongitudeFixModel());
|
||||||
// mtvPostionFixModelInfo.setText(szTemp);
|
//// mtvPostionFixModelInfo.setText(szTemp);
|
||||||
// LogUtils.d(TAG, szTemp);
|
//// LogUtils.d(TAG, szTemp);
|
||||||
PostionFixModel.savePostionFixModel(mPostionFixModel);
|
// PostionFixModel.savePostionFixModel(mPostionFixModel);
|
||||||
//ToastUtils.show(szTemp);
|
// //ToastUtils.show(szTemp);
|
||||||
LogUtils.d(TAG, String.format("updatePostionFixModel() run %d", nCurrentFixActivationCountValue));
|
// LogUtils.d(TAG, String.format("updatePostionFixModel() run %d", nCurrentFixActivationCountValue));
|
||||||
|
//
|
||||||
showPostionFixModelInfo();
|
// showPostionFixModelInfo();
|
||||||
} else {
|
// } else {
|
||||||
// 定位修复模型数据定型, GPS定位监听停止
|
// // 定位修复模型数据定型, GPS定位监听停止
|
||||||
// 在需要停止监听的地方(如onPause/onDestroy)添加:
|
// // 在需要停止监听的地方(如onPause/onDestroy)添加:
|
||||||
if (locationManagerPhoneGPS != null) {
|
// if (locationManagerPhoneGPS != null) {
|
||||||
// 取消位置更新监听
|
// // 取消位置更新监听
|
||||||
locationManagerPhoneGPS.removeUpdates(phoneGPSLocationListener);
|
// locationManagerPhoneGPS.removeUpdates(phoneGPSLocationListener);
|
||||||
// 可选:停止后释放资源
|
// // 可选:停止后释放资源
|
||||||
phoneGPSLocationListener = null;
|
// phoneGPSLocationListener = null;
|
||||||
}
|
// }
|
||||||
LogUtils.d(TAG, String.format("updatePostionFixModel() stop %d", nCurrentFixActivationCountValue));
|
// LogUtils.d(TAG, String.format("updatePostionFixModel() stop %d", nCurrentFixActivationCountValue));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
private Location fixGPSLocationFromPostionFixModel(Location location) {
|
private Location fixGPSLocationFromPostionFixModel(Location location) {
|
||||||
// 用腾讯定位数据与GPS定位数据的数据差修复模型,来修复一下GPS定位数据。
|
// 用腾讯定位数据与GPS定位数据的数据差修复模型,来修复一下GPS定位数据。
|
||||||
@ -356,15 +389,15 @@ public class PositionsFragment extends Fragment {
|
|||||||
// tvGPSLocation.setText(String.format("GPS [ Latitude: %f \nLongitude: %f ]", latitudeGPSLock, longitudeGPSLock));
|
// tvGPSLocation.setText(String.format("GPS [ Latitude: %f \nLongitude: %f ]", latitudeGPSLock, longitudeGPSLock));
|
||||||
// fuseLocationData();
|
// fuseLocationData();
|
||||||
|
|
||||||
_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);
|
||||||
showLocationPhoneGPS();
|
//showLocationPhoneGPS();
|
||||||
updatePostionFixModel();
|
//updatePostionFixModel();
|
||||||
if(mswTaskService.isChecked()) {
|
if(mswTaskService.isChecked()) {
|
||||||
moveToCurrentLocation();
|
moveToCurrentLocation();
|
||||||
}
|
}
|
||||||
@ -389,29 +422,51 @@ public class PositionsFragment extends Fragment {
|
|||||||
//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;
|
// public static final int INIT_POSITION = 1;
|
||||||
class MyHandler extends Handler {
|
// class MyHandler extends Handler {
|
||||||
|
// @Override
|
||||||
|
// public void handleMessage(@NonNull Message msg) {
|
||||||
|
// switch (msg.what) {
|
||||||
|
// case INIT_POSITION:
|
||||||
|
// // 在这里处理接收到消息后的逻辑,比如更新 UI
|
||||||
|
// mLocationTX = (Location)msg.obj;
|
||||||
|
// //showLocationTX();
|
||||||
|
//
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// public void sendInitPositioningMessage(Location location) {
|
||||||
|
// if (mMyHandler != null) {
|
||||||
|
// Message message = Message.obtain();
|
||||||
|
// message.what = INIT_POSITION;
|
||||||
|
// message.obj = location;
|
||||||
|
// mMyHandler.sendMessage(message);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
private class MyServiceConnection implements ServiceConnection {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(@NonNull Message msg) {
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
switch (msg.what) {
|
LogUtils.d(TAG, "onServiceConnected(...)");
|
||||||
case INIT_POSITION:
|
GPSService.MyBinder binder = (GPSService.MyBinder) service;
|
||||||
// 在这里处理接收到消息后的逻辑,比如更新 UI
|
mGPSService = binder.getService();
|
||||||
_LocationTX = (Location)msg.obj;
|
mGPSService.setOnGPSRTLocationListener(new OnGPSRTLocationListener(){
|
||||||
showLocationTX();
|
@Override
|
||||||
|
public void onGPSRTLocation(Location location) {
|
||||||
break;
|
showLocationPhoneGPS(location);
|
||||||
default:
|
}
|
||||||
break;
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
public static void sendInitPositioningMessage(Location location) {
|
@Override
|
||||||
if (_MyHandler != null) {
|
public void onServiceDisconnected(ComponentName name) {
|
||||||
Message message = Message.obtain();
|
LogUtils.d(TAG, "onServiceDisconnected(...)");
|
||||||
message.what = INIT_POSITION;
|
mGPSService = null;
|
||||||
message.obj = location;
|
|
||||||
_MyHandler.sendMessage(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,7 @@ import com.tencent.tencentmap.mapsdk.maps.model.Marker;
|
|||||||
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
|
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
|
||||||
import com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle;
|
import com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import cc.winboll.studio.positions.listeners.OnTXRTLocationListener;
|
||||||
|
|
||||||
public class TXMSFragment extends Fragment implements /*EasyPermissions.PermissionCallbacks,*/LocationSource, TencentLocationListener,TencentMap.OnMapClickListener {
|
public class TXMSFragment extends Fragment implements /*EasyPermissions.PermissionCallbacks,*/LocationSource, TencentLocationListener,TencentMap.OnMapClickListener {
|
||||||
|
|
||||||
@ -78,7 +79,8 @@ public class TXMSFragment extends Fragment implements /*EasyPermissions.Permissi
|
|||||||
ArrayList<PostionModel> locationPostionModelList;
|
ArrayList<PostionModel> locationPostionModelList;
|
||||||
//Location lastLocation;
|
//Location lastLocation;
|
||||||
static TXMSFragment _TXMSFragment;
|
static TXMSFragment _TXMSFragment;
|
||||||
|
OnTXRTLocationListener mOnTXRTLocationListener;
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
@ -369,8 +371,10 @@ public class TXMSFragment extends Fragment implements /*EasyPermissions.Permissi
|
|||||||
message.what = TXMSFragment.REALTIME_POSITIONING;
|
message.what = TXMSFragment.REALTIME_POSITIONING;
|
||||||
handler.sendMessage(message);
|
handler.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setOnTXRTLocationListener(OnTXRTLocationListener listener) {
|
||||||
|
mOnTXRTLocationListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -435,7 +439,8 @@ public class TXMSFragment extends Fragment implements /*EasyPermissions.Permissi
|
|||||||
// lastLocation.setLongitude(tencentLocation.getLongitude());
|
// lastLocation.setLongitude(tencentLocation.getLongitude());
|
||||||
// lastLocation.setAccuracy(tencentLocation.getAccuracy());
|
// lastLocation.setAccuracy(tencentLocation.getAccuracy());
|
||||||
|
|
||||||
PositionsFragment.sendInitPositioningMessage(locationTX);
|
//PositionsFragment.sendInitPositioningMessage(locationTX);
|
||||||
|
mOnTXRTLocationListener.onTXRTLocation(locationTX);
|
||||||
|
|
||||||
// 当不再需要定位时
|
// 当不再需要定位时
|
||||||
// 取消定位监听
|
// 取消定位监听
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
package cc.winboll.studio.positions.listeners;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen@AliYun.Com
|
||||||
|
* @Date 2025/04/03 14:01:18
|
||||||
|
* @Describe 手机 GPS 实时位置监听类
|
||||||
|
*/
|
||||||
|
import android.location.Location;
|
||||||
|
|
||||||
|
public interface OnGPSRTLocationListener {
|
||||||
|
|
||||||
|
public static final String TAG = "OnGPSRTLocationListener";
|
||||||
|
|
||||||
|
void onGPSRTLocation(Location location);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package cc.winboll.studio.positions.listeners;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen@AliYun.Com
|
||||||
|
* @Date 2025/04/03 13:06:13
|
||||||
|
* @Describe 位置监听类
|
||||||
|
*/
|
||||||
|
import android.location.Location;
|
||||||
|
|
||||||
|
public interface OnTXRTLocationListener {
|
||||||
|
|
||||||
|
public static final String TAG = "OnTXRTLocationListener";
|
||||||
|
|
||||||
|
void onTXRTLocation(Location location);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,108 @@
|
|||||||
|
package cc.winboll.studio.positions.services;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
|
import android.app.Service;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.location.Location;
|
||||||
|
import android.location.LocationListener;
|
||||||
|
import android.location.LocationManager;
|
||||||
|
import android.os.Binder;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import androidx.core.app.ActivityCompat;
|
||||||
|
import cc.winboll.studio.positions.listeners.OnGPSRTLocationListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen@AliYun.Com
|
||||||
|
* @Date 2025/04/03 12:13:23
|
||||||
|
* @Describe 获取实时 GPS 数据的服务
|
||||||
|
*/
|
||||||
|
public class GPSService extends Service {
|
||||||
|
|
||||||
|
public static final String TAG = "GPSService";
|
||||||
|
|
||||||
|
OnGPSRTLocationListener mOnGPSRTLocationListener;
|
||||||
|
LocationManager locationManager;
|
||||||
|
Location mLocationPhoneGPS;
|
||||||
|
Location mLocationNetwork;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBinder onBind(Intent intent) {
|
||||||
|
return new MyBinder();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用于返回服务实例的Binder
|
||||||
|
public class MyBinder extends Binder {
|
||||||
|
public GPSService getService() {
|
||||||
|
return GPSService.this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
super.onCreate();
|
||||||
|
|
||||||
|
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||||
|
// 请求GPS定位
|
||||||
|
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, phoneGPSLocationListener);
|
||||||
|
// 请求基站(网络)定位
|
||||||
|
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, networkLocationListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
if (locationManager != null) {
|
||||||
|
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
|
||||||
|
ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
locationManager.removeUpdates(phoneGPSLocationListener);
|
||||||
|
locationManager.removeUpdates(networkLocationListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnGPSRTLocationListener(OnGPSRTLocationListener listener) {
|
||||||
|
mOnGPSRTLocationListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LocationListener phoneGPSLocationListener = new LocationListener() {
|
||||||
|
@Override
|
||||||
|
public void onLocationChanged(Location location) {
|
||||||
|
// 处理GPS定位结果
|
||||||
|
if (location != null && mOnGPSRTLocationListener != null) {
|
||||||
|
mLocationPhoneGPS = location;
|
||||||
|
mOnGPSRTLocationListener.onGPSRTLocation(mLocationPhoneGPS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStatusChanged(String provider, int status, Bundle extras) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderEnabled(String provider) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderDisabled(String provider) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
private LocationListener networkLocationListener = new LocationListener() {
|
||||||
|
@Override
|
||||||
|
public void onLocationChanged(Location location) {
|
||||||
|
// 处理基站(网络)定位结果
|
||||||
|
if (location != null) {
|
||||||
|
mLocationNetwork = location;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStatusChanged(String provider, int status, Bundle extras) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderEnabled(String provider) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProviderDisabled(String provider) {}
|
||||||
|
};
|
||||||
|
}
|
@ -6,110 +6,44 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1.0">
|
|
||||||
|
|
||||||
<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>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<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="#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>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="150dp">
|
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
|
<LinearLayout
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="150dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="10dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Text"
|
||||||
|
android:id="@+id/txmylocationinfo_tv"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="10dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Text"
|
||||||
|
android:id="@+id/phonegpsinfo_tv"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user