2010-11-18 18 views
0

我有这个问题,我认为mimapmap项目的位置,但是当我移动或缩放时它们只会重新绘制地图...我更新mimapmap项目的位置,但当我移动或缩放地图时,它们只会重新绘制

我想,每次possitions得到了更新,那么他们得到重新绘制在地图上,而无需移动或用手指

我怎么能做到这一点放大它的时间?

无效是没有答案的,因为它使所有的完全重绘,需要重新下载从互联网地图...

我的代码:

public class Locate extends MapActivity{ 

private TextView userText = null; 
private TextView permissionText = null; 
private TextView lastUpdateText = null; 
private Button locateButton = null; 
private Button traceButton = null; 
private MapView mapView = null; 
List<Overlay> mapOverlays = null; 
double lat; 
double lng; 
GeoPoint p; 
MapController mc; 

Drawable drawable; 
Drawable drawable2; 
MyItemizedOverlay itemizedoverlay; 
MyItemizedOverlay itemizedoverlay2; 

//para almacenar la config local de mi app, mostrarme o no en el mapa... 
static SharedPreferences settings; 
static SharedPreferences.Editor configEditor; 

//private MyLooper mLooper; 

////////////////////////////////////////MANEJADOR SIMILAR A UN HILO, QUE ME PERMITE RECOGER MI POSICION ACTUAL Y ACTUALIZARLA EN EL MAPA UNA VEZ CADA 5 SEGUNDOS 
private Handler mHandler; 
private Runnable updateRunnable = new Runnable() { 
    @Override public void run() { 
     itemizedoverlay2.clear(); 
     updateMyPosition(); 
     queueRunnable(); 
    } 
}; 
private void queueRunnable() { 
    mHandler.postDelayed(updateRunnable, 5000); 
} 
/////////////////////////////////////////FIN MANEJADOR 

public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.locate); 

    userText = (TextView) findViewById(R.id.User); 
    permissionText= (TextView) findViewById(R.id.Permission); 
    lastUpdateText= (TextView) findViewById(R.id.LastUpdate); 
    locateButton = (Button) findViewById(R.id.locate); 
    traceButton = (Button) findViewById(R.id.trace); 
    mapView = (MapView) findViewById(R.id.mapview); 
    mapView.setBuiltInZoomControls(true); 
    mapOverlays = mapView.getOverlays(); 
    mc = mapView.getController(); 

    settings=PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()); 
    configEditor = settings.edit(); 

    drawable = this.getResources().getDrawable(R.drawable.minifriend); // Icono de la cara, para posiciones de mis amigos 
    drawable2 = this.getResources().getDrawable(R.drawable.miniicon2); // Icono del programa, para mi posicion GPS 
    itemizedoverlay = new MyItemizedOverlay(drawable, this); // Aqui almaceno otras posiciones gps 
    itemizedoverlay2 = new MyItemizedOverlay(drawable2, this); // Aqui almaceno mi posicion gps 

    if (this.getIntent().getExtras() != null) /// si he recibido datos del friend en el Bundle 
    { 
     updateFriendPosition(); 
    } 

    if (settings.getBoolean("showMeCheckBox", true)) 
    { 
     updateMyPosition(); 
    } 


    locateButton.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      // Perform action on clicks 
      //itemizedoverlay2.getItem(0). 
      itemizedoverlay.clear(); 
      updateFriendPosition(); 
      itemizedoverlay2.clear(); 
      updateMyPosition(); 
     } 
    }); 

    traceButton.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      // Perform action on clicks    
     } 
    }); 

    /////////////////////////////////////////////////////////////////////////////////////////// 
    /// CODIGO PARA QUITAR EL FOCO DEL PRIMER TEXTEDIT Y QUE NO SALGA EL TECLADO DE ANDROID /// 
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 
    /////////////////////////////////////////////////////////////////////////////////////////// 

    //Thread thread = new Thread(this); 
    //thread.start(); 

    //mLooper = new MyLooper(); 
    //mLooper.start(); 

    ////////////////////////////////////////MANEJADOR SIMILAR A UN HILO, QUE ME PERMITE RECOGER MI POSICION ACTUAL Y ACTUALIZARLA EN EL MAPA UNA VEZ CADA 5 SEGUNDOS 
    mHandler = new Handler(); 
    queueRunnable(); 
    /////////////////////////////////////// FIN MANEJADOR 

} 
private void updateFriendPosition() 
{ 
    Bundle bundle = this.getIntent().getExtras();//get the intent & bundle passed by X 
    userText.setText(bundle.getString("user")); 
    permissionText.setText(bundle.getString("permission")); 
    lastUpdateText.setText(bundle.getString("lastupdate")); 
    String coordinates[] = {bundle.getString("lat"), bundle.getString("lon")}; 
    lat = Double.parseDouble(coordinates[0]); 
    lng = Double.parseDouble(coordinates[1]); 
    p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); 
    OverlayItem overlayitem1 = new OverlayItem(p, bundle.getString("user"), "Hi Friend!"); 
    itemizedoverlay.addOverlay(overlayitem1); 
    mapOverlays.add(itemizedoverlay);// dibujo la estrella con la posicion actual del friend 

    mc.animateTo(p); ///nos centra el mapa en la posicion donde esta nuestro amigo 
    mc.setZoom(10); /// ajusta el zoom a 10   
} 
public void updateMyPosition() 
{ 
    Object LOCK = new Object(); 
    synchronized (LOCK){ 
    String coordinates[] = {settings.getString("mylatitude", null),settings.getString("mylongitude", null)};  
    lat = Double.parseDouble(coordinates[0]); 
    lng = Double.parseDouble(coordinates[1]); 
    p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); 
    OverlayItem overlayitem1 = new OverlayItem(p, "Me", "My Position"); 
    itemizedoverlay2.addOverlay(overlayitem1); 
    mapOverlays.add(itemizedoverlay2);//dibujo mi icono para mostrarme a mi 
    } 
} 

回答

2

您正在修改的地图的覆盖列表。从文档getOverlays()

如果您修改列表,你会 可能需要调用 View.postInvalidate(),使 变化将是可见的 用户。

+0

我用mapView.invalidate()解决了它,它不重绘所有的地图,只有项目! – NullPointerException 2010-11-22 10:22:56

相关问题