0

パスを描画し、移動時に距離を計算する方法。以下のコードは、onLocationChanged メソッドで距離を計算しませんか??

public void onLocationChanged(Location location) {
    // TODO Auto-generated method stub

    String text = String.format("Lat:\t %f\nLong:\t %f\nAlt:\t %f\nBearing:\t %f\nDistance:\t %f",
            location.getLatitude() *1E6, location.getLongitude() *1E6,
            location.getAltitude() *1E6, location.getBearing() *1E6, location.distanceTo(location));
            textOut.setText(text);
    lat = (int) (location.getLatitude() *1E6);
    longi = (int) (location.getLongitude() *1E6);
    GeoPoint myLocation = new GeoPoint(lat, longi);
    OverlayItem overlayItem = new OverlayItem(myLocation, "WHATZ UP", "2nd String");
    StagePoint custom = new StagePoint(d, Start.this);
    custom.insertPinpoint(overlayItem);
    overlayList.add(custom);
}   
4

1 に答える 1

0
private class MyLocationOverlay1 extends MyLocationOverlay {
@Override
public void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) 
        super.drawMyLocation(canvas,mapView,lastFix,myLocation,when);

        Location bLocation = new Location("reverseGeocoded");
        bLocation.setLatitude(FindList.gpslat);           
        bLocation.setLongitude(FindList.gpslong);         
        Location aLocation = new Location("reverseGeocoded");
        aLocation.setLatitude(myLocation.getLatitudeE6() / 1e6);
        aLocation.setLongitude(myLocation.getLongitudeE6() / 1e6);

        int distance = (int)aLocation.distanceTo(bLocation);  
        String str = " (" + String.valueOf(distance) + " meters)";
}
}
于 2012-05-02T09:58:30.607 に答える