是的,上代码 public class TextOverlay extends Overlay { /* er pour la postion actuellement */ //public GeoPoint geoPointActuellement = null; private Bitmap bmp = null; private Point deviation = null;
private final int rayon = 5; // un point marque sur l'endroit qu'on veut marquer
/** * La BDD */ //public GeoPoint geoPointActuellement; private BatimentBDD bdd; private List<Batiment> listBatiments; public TPReality app;
public TextOverlay(TPReality tpReality) { this.app = tpReality; }
@Override public void draw(Canvas canvas, MapView mapView, boolean shadow){ Projection projection = mapView.getProjection(); if (shadow == false){ bdd = new BatimentBDD(app); bdd.open(); listBatiments = bdd.listBatiments(); bdd.close();
// le parametre pour dessiner dans le overlay Paint paint = new Paint(); paint.setARGB(250, 250, 0, 0); // couleur paint.setAntiAlias(true); // lisse paint.setFakeBoldText(true); // textView bold
for (Batiment b: listBatiments){ GeoPoint geoPoint = new GeoPoint(b.getLatitude(), b.getLongitude()); Point point = new Point(); projection.toPixels(geoPoint, point); // dessine un point rayon = 5 RectF oval = new RectF(point.x - rayon ,point.y - rayon, point.x+rayon, point.y + rayon); canvas.drawOval(oval,paint); canvas.drawText(b.getNom(), point.x + 2*rayon, point.y, paint); } }
super.draw(canvas, mapView, shadow); }如上代码,只看红色即可。有个overlay 这个类,包含一个draw 方法。但是在mapactivity 里面并没有调用draw 方法,而是在mapView 的实例里添加了overlay 的实例后(通过 // get le couche de overlay googlemap List<Overlay> overlays = mapView.getOverlays(); // dessiner les infos sur le map textOverlay = new TextOverlay(this); // ajoute overlay dans le mapView overlays.add(textOverlay); 实现),就可实现画的工作。 现在的问题是我有一个listener 可以随时监听GPS 数值的变化,然后我也知道怎么去绘制一个图片,但是不知道怎么去加载这个图片。(应该不是去调用draw 这个方法,而是把overlay 添加到mapview里)请大家多多指教。 谢谢楼上的回答,但能不能说的仔细点。
public class TextOverlay extends Overlay {
/* er pour la postion actuellement */
//public GeoPoint geoPointActuellement = null;
private Bitmap bmp = null;
private Point deviation = null;
private final int rayon = 5; // un point marque sur l'endroit qu'on veut marquer
/**
* La BDD
*/
//public GeoPoint geoPointActuellement;
private BatimentBDD bdd;
private List<Batiment> listBatiments;
public TPReality app;
public TextOverlay(TPReality tpReality) {
this.app = tpReality;
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow){
Projection projection = mapView.getProjection();
if (shadow == false){
bdd = new BatimentBDD(app);
bdd.open();
listBatiments = bdd.listBatiments();
bdd.close();
// le parametre pour dessiner dans le overlay
Paint paint = new Paint();
paint.setARGB(250, 250, 0, 0); // couleur
paint.setAntiAlias(true); // lisse
paint.setFakeBoldText(true); // textView bold
for (Batiment b: listBatiments){
GeoPoint geoPoint = new GeoPoint(b.getLatitude(), b.getLongitude());
Point point = new Point();
projection.toPixels(geoPoint, point);
// dessine un point rayon = 5
RectF oval = new RectF(point.x - rayon ,point.y - rayon, point.x+rayon, point.y + rayon);
canvas.drawOval(oval,paint);
canvas.drawText(b.getNom(), point.x + 2*rayon, point.y, paint);
}
}
super.draw(canvas, mapView, shadow);
}如上代码,只看红色即可。有个overlay 这个类,包含一个draw 方法。但是在mapactivity 里面并没有调用draw 方法,而是在mapView 的实例里添加了overlay 的实例后(通过
// get le couche de overlay googlemap
List<Overlay> overlays = mapView.getOverlays();
// dessiner les infos sur le map
textOverlay = new TextOverlay(this);
// ajoute overlay dans le mapView
overlays.add(textOverlay); 实现),就可实现画的工作。
现在的问题是我有一个listener 可以随时监听GPS 数值的变化,然后我也知道怎么去绘制一个图片,但是不知道怎么去加载这个图片。(应该不是去调用draw 这个方法,而是把overlay 添加到mapview里)请大家多多指教。
谢谢楼上的回答,但能不能说的仔细点。
http://disanji.net/2011/02/20/android-google-map-2/
谢谢一楼的。分给你。