gpt4 book ai didi

android - 如何在后台线程启动GPS定位?

转载 作者:行者123 更新时间:2023-11-29 02:08:17 25 4
gpt4 key购买 nike

我需要在单独的线程中使用 GPS 检索当前位置。

最佳答案

学习下面的代码,

public class LocListener implements LocationListener {
private static double lat =0.0;
private static double lon = 0.0;
private static double alt = 0.0;
private static double speed = 0.0;

public static double getLat()
{
return lat;
}

public static double getLon()
{
return lon;
}

public static double getAlt()
{
return alt;
}

public static double getSpeed()
{
return speed;
}

@Override
public void onLocationChanged(Location location)
{
lat = location.getLatitude();
lon = location.getLongitude();
alt = location.getAltitude();
speed = location.getSpeed();
}

@Override
public void onProviderDisabled(String provider) {}
@Override
public void onProviderEnabled(String provider) {}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
}

现在使用此代码在线程中启动 gps。

new Thread ( new Runnable()
{
public void run()
{
locationManager = ( LocationManager ) getSystemService ( Context.LOCATION_SERVICE );
locationListener = new LocListener();
locationManager.requestLocationUpdates ( LocationManager.GPS_PROVIDER, 0, 0, locationListener );
}
}).start();

关于android - 如何在后台线程启动GPS定位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8769043/

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