gpt4 book ai didi

java - 代号一 GPS 追踪器

转载 作者:行者123 更新时间:2023-11-30 08:04:49 27 4
gpt4 key购买 nike

我想用 GPS 信号跟踪设备。同时显示纬度、经度、高度和速度。

我使用这段代码,但屏幕上没有结果:

@Override
protected void onGpsTracker_ButtonAction(Component c, ActionEvent event) {
try {
int i = 0;
Location loc = mylocLocationManager.getCurrentLocation();
if(loc.getStatus()==LocationManager.AVAILABLE) {
} else {
Dialog.show("Error!", "Falla de señal", "OK", null);
}
mylocLocationManager.setLocationListener(new LocationListener() {
public void locationUpdated(Location location) {
gpsLocation= location;
Component c = null;
Label labelalt = (Label)findByName("altitudT", c);
Label labellat = (Label)findByName("latitudT", c);
Label labellng = (Label)findByName("longitudT", c);
Label labeldist = (Label)findByName("distanciaT", c);
Label labelspeed = (Label)findByName("speedT", c);
altmax= location.getAltitude();
double lat = location.getLatitude();
double lng = location.getLongitude();
float speed = location.getVelocity();

double alt = location.getAltitude();
velprompos = velprompos + 1;
totspeed = (int) (totspeed + speed);
velopro = totspeed / velprompos;
totalt = altmax - alt;

velmax=speed;
Coord lastLocation = new Coord(lat, lng);
mapComponent.zoomTo(lastLocation, 15);

prevdistance = totdistance;
prevLon = currentLon;
prevLat = currentLat;
String Salt = String.valueOf(alt);
labelalt.setText(Salt);
String Slat = String.valueOf(lat);
labellat.setText(Slat);
String Slng = String.valueOf(lng);
labellng.setText(Slng);
String Sspeed = String.valueOf(speed);
labelspeed.setText(Sspeed);

//aca hay q pner dibujo lineas
}

public void providerStateChanged(int newState) {
//positionMethod();
}
});
} catch (Exception ex) {
ex.printStackTrace();
gpsLocation = null;
}
}

想法是在设备移动时获取位置,并将此结果显示在一些标签上。有帮助吗?

最佳答案

您错误地实现了几件事。

  1. @override 添加到重写方法,如 locationUpdatedproviderStateChanged

  2. 不要重新声明 Component c as 并将其设置为 null

  3. 通过使用 find 方法直接调用它们并传递 c 作为参数来获取标签

  4. 在每次更新后重新验证重新绘制您的表单。

  5. 作为一般性建议,保持变量声明的一致性,将 Number of Mangoes 声明为 numOfMangoes不是 numberofmangoes numofmangoesNumberofmangoes

    @Override
    protected void onGpsTracker_ButtonAction(Component c, ActionEvent event) {
    try {
    int i = 0;
    Location loc = mylocLocationManager.getCurrentLocation();
    if (loc.getStatus() == LocationManager.AVAILABLE) {
    System.out.println("Location available");
    } else {
    Dialog.show("Error!", "Falla de señal", "OK", null);
    }
    final LocationManager mylocLocationManager = LocationManager.getLocationManager();
    mylocLocationManager.setLocationListener(new LocationListener() {
    @Override
    public void locationUpdated(Location location) {
    gpsLocation = location;
    Label labelspeed = ;
    altmax = location.getAltitude();
    double lat = location.getLatitude();
    double lng = location.getLongitude();
    float speed = location.getVelocity();

    double alt = location.getAltitude();
    velprompos = velprompos + 1;
    totspeed = (int) (totspeed + speed);
    velopro = totspeed / velprompos;
    totalt = altmax - alt;

    velmax = speed;
    Coord lastLocation = new Coord(lat, lng);
    mapComponent.zoomTo(lastLocation, 15);

    prevdistance = totdistance;
    prevLon = currentLon;
    prevLat = currentLat;
    String Salt = String.valueOf(alt);
    findAltitudT(c).setText(Salt);
    String Slat = String.valueOf(lat);
    findLatitudT(c).setText(Slat);
    String Slng = String.valueOf(lng);
    findLongitudT(c).setText(Slng);
    String Sspeed = String.valueOf(speed);
    findSpeedT(c).setText(Sspeed);

    c.getComponentForm().revalidate();
    //aca hay q pner dibujo lineas
    }

    @Override
    public void providerStateChanged(int newState) {
    //positionMethod();
    }
    });

    } catch (Exception ex) {
    ex.printStackTrace();
    gpsLocation = null;
    }
    }

关于java - 代号一 GPS 追踪器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35387372/

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