谷歌地图:在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();
}
});
我的初始代码中没有制造商,覆盖层具有所需的所有良好参数,已加载到 onCreate () 方法中并且可以正常工作很好,但正如我提到的,我不知道如何在 onclick ()
方法中添加标记。我知道我做错了,但我不知道该怎么做:(
提前谢谢
i'm currently having trouble to add dynamicly a marquer on my mapview, certainly due to my lack in java knowledge :(
which parameter should i give to my canvas to make this work?
when i fee the coordinates, the map goes where i want but i have no maker
((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();
}
});
in my intial code, the overlay which has all good parametres it needs, is loaded in the onCreate ()
methode and it works fine but as i mentioned i can't figure out how to add the marker in the onclick ()
methode. I know what i did is wrong but i don't know how to do :(
thx in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在实际将纬度/经度转换为屏幕坐标之前,您正在使用 screenP3ts 绘制到画布上。你需要这个:
You are drawing to the canvas using
screenP3ts
before you actually transform the lat / lon into screen coordinates. You need this: