2012-05-02 113 views
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); 
} 

回答

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)"; 
} 
} 
+0

非常感謝達拉爾, 「FindList。」得到了一個錯誤.plz灑了一些光,我會非常感激。其他人給了我一個前進的方向 –