gpt4 book ai didi

安卓实时位置追踪

转载 作者:行者123 更新时间:2023-12-05 07:57:28 25 4
gpt4 key购买 nike

大家好,我正在开发两个应用程序,一个是为管理员开发的,另一个是为员工开发的。现在我想使用这个应用程序跟踪员工设备,当员工设备的位置发生变化时,位置会发送到服务器。仅当位置发生变化时才会发送位置。位置更改时如何将设备位置发送到服务器? 其次,我想在管理应用程序 map 上显示员工的位置,因为它正在更改其位置。(我可以通过 GCM 或任何其他技术将位置坐标从服务器发送到管理应用程序吗?)

嘿,投票失败者,你能解释一下这个问题有什么问题吗?如果您对问题有答案,请尝试理解问题。请帮忙提前致谢..

最佳答案

public LatLng getLocation()
{
// Get the location manager
MyLocationListener myLocListener = new MyLocationListener();
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(bestProvider);
locationManager.requestLocationUpdates(bestProvider,timeAfteryougetUpdate, minDistanceAfterYougetupdate, myLocListener);
Double lat,lon;
try {
lat = location.getLatitude ();
lon = location.getLongitude ();
return new LatLng(lat, lon);
}
catch (NullPointerException e){
e.printStackTrace();
return null;
}
}

**使用它来获取位置**

private class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc)
{
if (loc != null)
{
// Do something knowing the location changed by the distance you requested
methodThatDoesSomethingWithNewLocation(loc);
}
}

@Override
public void onProviderDisabled(String arg0)
{
// Do something here if you would like to know when the provider is disabled by the user
}

@Override
public void onProviderEnabled(String arg0)
{
// Do something here if you would like to know when the provider is enabled by the user
}

@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2)
{
// Do something here if you would like to know when the provider status changes
}
}

关于安卓实时位置追踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27119877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com