我目前无法在我的 map View 上动态添加标记,这当然是由于我缺乏 Java 知识:(
我应该给 Canvas 提供哪个参数才能完成这项工作? 当我输入坐标时, map 会转到我想要的地方,但我没有制造商
((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 ()
方法中,并且工作正常,但正如我提到的,我不知道如何添加onclick ()
方法中的标记。我知道我做错了,但我不知道该怎么做:(
提前致谢
最佳答案
在实际将纬度/经度转换为屏幕坐标之前,您正在使用 screenP3ts 绘制到 Canvas 上。你需要这个:
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);
关于java - 谷歌地图 : dynamic canvas drawing in mapview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9214939/