2012-02-09 74 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