2012-02-09 73 views
0

目前我遇到麻煩,動態地添加marquer我MapView的,當然動態畫布繪製,由於我缺乏的Java知識:(谷歌地圖:在圖形頁面

,我應該給我的畫布,其參數,使這項工作? 當我費座標,地圖飛到哪裏,我想,但我不壺

((Button)findViewById(R.id.goMap)).setOnClickListener(
         new OnClickListener() { 
        @Override 
        public void onClick(View v) { 



          mapView.invalidate(); 
         // On récupère notre EditText 
         EditText UserName = ((EditText)findViewById(R.id.getLon)); 
         EditText Password = ((EditText)findViewById(R.id.getLat)); 

         // On garde la chaîne de caractères 
          _lat = UserName.getText().toString(); 
          _long = Password.getText().toString(); 

         latTest = Double.parseDouble(_lat)* 1E6; 
         longTest = Double.parseDouble(_long)* 1E6; 

         p3 = new GeoPoint(
            (int) (latTest), 
            (int) (longTest)); 

          //---add the marker--- 
          Bitmap bmp3 = BitmapFactory.decodeResource(
           getResources(), R.drawable.maps_position_marker); 
          Canvas canvas= new Canvas(); 
          canvas.drawBitmap(bmp3, screenP3ts.x-15, screenP3ts.y-30, null); 


         mapView.getProjection().toPixels(p3, screenP3ts); 
          mapController.animateTo(p3); 
          mapController.setCenter(p3); 

         Toast.makeText(TheMap.this, "lat=" + latTest + " et " + "long= " + longTest, Toast.LENGTH_SHORT).show(); 


         } 
         }); 
在我INTIAL代碼

,它有它需要所有好的參數應用覆蓋,被裝載在onCreate()梅索德和它工作正常,但正如我所提到的,我無法弄清楚如何在onclick()方法中添加標記德。我知道我所做的是錯的,但我不知道該怎麼辦:(

THX提前

回答

1

您正在使用screenP3ts你真正轉變之前畫到畫布上經/緯度到屏幕座標。您需要這樣:

Bitmap bmp3 = BitmapFactory.decodeResource(
     getResources(), R.drawable.maps_position_marker); 
Canvas canvas= new Canvas(); 

mapView.getProjection().toPixels(p3, screenP3ts); 
canvas.drawBitmap(bmp3, screenP3ts.x-15, screenP3ts.y-30, null); 
+0

非常感謝,現在它的工作原理 – youssoua 2012-02-09 16:55:58

+0

你知道如何解決在那個特定點圖片 ,因爲當我移動地圖時,的ressource不留固定在feeded座標 – youssoua 2012-02-09 18:31:25

+0

?每次地圖移動時,您都需要獲取更新的屏幕座標o這實際上是重寫'onDraw()'方法。 – CaseyB 2012-02-09 18:54:59