2
我想用GPS信號跟蹤設備。同時顯示緯度,經度,高度和速度。Codename one GPS tracker
我用這個代碼並且在屏幕上沒有任何結果:
@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;
}
}
的想法是讓當設備被移動的位置,並顯示這導致一些標籤。任何幫助?
我能說什麼,你又做了一次。正確的答案和完美的解釋! –