我需要添加一个弹出窗口,在我添加的标记之上显示城市名称(自己的描述),下面是我的标记代码。任何帮助将不胜感激。
private MapView osm;
osm = (MapView) findViewById(R.id.mapView);
public void addMarker() {
GeoPoint colombo = new GeoPoint(6.9271, 79.8612);
Marker startMarker = new Marker(osm);
startMarker.setPosition(colombo);
osm.getOverlays().add(startMarker);
startMarker.setIcon(getResources().getDrawable(R.drawable.black));
}
答案 0 :(得分:0)
startMarker.setTitle("title")
应该做的...你可以通过在startMarker上调用showInfoWindow()
方法手动显示它。
如果您想拥有自己的弹出窗口布局,可以继承InfoWindow
。
答案 1 :(得分:0)
MarkerWithLabel 对其进行分类:
public class MarkerWithLabel extends Marker {
Paint textPaint = null;
String mLabel = null;
float rotation = 0.0f;
public MarkerWithLabel( MapView mapView, String label) {
super( mapView);
mLabel = label;
textPaint = new Paint();
textPaint.setColor( Color.RED);
textPaint.setTextSize( WaypointActivity.textSizeCanvas25sp);
textPaint.setAntiAlias(true);
textPaint.setTextAlign(Paint.Align.LEFT);
setTitle( label);
}
public void draw( final Canvas c, final MapView osmv, boolean shadow) {
draw( c, osmv);
}
public void draw( final Canvas c, final MapView osmv) {
super.draw( c, osmv, false);
Point p = this.mPositionPixels; // already provisioned by Marker
if( rotation <= -1 || rotation >= 1) { // could be left out
c.save();
c.rotate( rotation, p.x, p.y);
c.drawText( getTitle(), p.x, p.y+20, textPaint);
c.restore();
} else {
c.drawText( getTitle(), p.x, p.y+20, textPaint);
}
}
}
查找所有MarkerWithLabel实例很容易:
marker = new MarkerWithLabel( mv, label);
marker.setTitle( label);