我目前无法在我的mapview上动态添加一个marquer,当然由于我缺乏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();
}
});
在我的初始代码中,具有所需的所有良好参数的叠加层被加载到onCreate ()
方法中并且它工作正常,但正如我所提到的,我无法弄清楚如何在{中添加标记{1}}方法。我知道我所做的是错的,但我不知道该怎么办:(
答案 0 :(得分:1)
在将lat / lon实际转换为屏幕坐标之前,使用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);