Android 地图,在该点上有一个文本视图并带有一个按钮
在我的应用程序中,我想显示一个带有指针的地图,在指针上方我想显示带有按钮的文本视图。使用该按钮我想转到下一个活动。以下是我显示该点的代码,但如何显示带有文本和右侧按钮的点。以及如何为其编写 btn 操作
class MapOverlay extends com.google.android.maps.Overlay
{
public boolean draw(Canvas canvas, MapView mapView,boolean shadow, long when)
{
super.draw(canvas, mapView, shadow);
//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.marker);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-100, null);
mapView.getProjection().toPixels(q, screenPts);
@SuppressWarnings("unused")
Bitmap bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.blue);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-100, null);
return true;
}
}
p = new GeoPoint((int) (latPt * 1E6),(int) (lngPt * 1E6));
Log.e("point p ",""+p);
mapController.animateTo(p);
mapController.setZoom(16);
mapView.invalidate();
mapView.setTraffic(true);
mapController = mapView.getController();
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
in my app i want to show a map with a pointer and above the pointer i want to show a text view with a button. Using that button i want to move to next activity. Following is my code to show the point, but how to show a point with text and button to right of it. And how to write the btn action for it
class MapOverlay extends com.google.android.maps.Overlay
{
public boolean draw(Canvas canvas, MapView mapView,boolean shadow, long when)
{
super.draw(canvas, mapView, shadow);
//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.marker);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-100, null);
mapView.getProjection().toPixels(q, screenPts);
@SuppressWarnings("unused")
Bitmap bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.blue);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-100, null);
return true;
}
}
p = new GeoPoint((int) (latPt * 1E6),(int) (lngPt * 1E6));
Log.e("point p ",""+p);
mapController.animateTo(p);
mapController.setZoom(16);
mapView.invalidate();
mapView.setTraffic(true);
mapController = mapView.getController();
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过使用视图而不是叠加来完成此操作,因此您可以使用 addItem 为地图中的每个项目添加一个新视图。这是代码:
AnnotationView
然后我刚刚创建它并添加到地图中,如下所示:
map_overlay 布局只是您想要在地图上显示为叠加层(图像、按钮...)的 linealayout
我只有一个问题缩放比例,因为缩放时点会发生一些变化,我正在尝试解决它。
希望有帮助
干杯
I did it by using views instead of overlays, so you add a new view for each item in your map with addItem. Here it is the code:
AnnotationView
Then I just created it and add to the map like:
The map_overlay layout is just the linealayout you want to display over the map as a overlay (images, buttons...)
I have only a problem with zoom scales, because the point changes a bit while zooming I am trying to solve it.
Hope that helps
Cheers