我有一个关于使导航应用程序更快、更稳定的问题。
我的应用程序的基本层是一个简单的地图视图,上面覆盖着几个叠加层(2 个标记用于起点和目的地,一个用于路线)。
我的想法是实现一个线程来显示路线,这样应用程序就不会在计算更复杂的路线时挂起(就像现在一样)。
实现线程后,不再显示更新,也许你可以帮助我看一下下面我的代码摘录:
private class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
posUser = new GeoPoint((int) (loc.getLatitude() * 1E6), (int) (loc
.getLongitude() * 1E6));
new Thread(){
public void run(){
mapView.invalidate();
// Erase old overlays
mapView.getOverlays().clear();
// Draw updated overlay elements and adjust basic map settings
updateText();
if(firstRefresh){
adjustMap();
firstRefresh = false;
}
getAndPaintRoute();
drawMarkers();
}
};
}
一些特性已经被总结为像“drawMarkers()”或“updateText()”这样的方法......(它们不需要更多关注;-))