我希望有人可以帮忙解决这个问题。我创建了一个地图应用程序,它在xml文件的位置上放置了一个图标,但是我需要使图标可以点击以打开有关该位置的信息页面。
目前我在类GPSLocationListener下实现了LocationListener:
MapOverlay mapOverlay = new MapOverlay();
mapOverlay.setPointToDraw(point, "pointer", null);
List<Overlay> listOfOverLays = mapView.getOverlays();
listOfOverLays.clear();
// doc is data from xml file
NodeList nodes = doc.getElementsByTagName("result");
listOfOverLays.add(mapOverlay);
for (int i = 0; i < nodes.getLength(); i++) {
Element e = (Element)nodes.item(i);
String locId = XMLfunctions.getValue(e, "id");
String aString = XMLfunctions.getValue(e, "lat");
double lat = Double.parseDouble(aString);
String bString = XMLfunctions.getValue(e, "long");
double longi = Double.parseDouble(bString);
// here, 'point' and mapOverlay have already been created and added
GeoPoint point2 = new GeoPoint((int) (lat * 1E6), (int) (longi * 1E6));
MapOverlay mapOverlay2 = new MapOverlay();
mapOverlay2.setPointToDraw(point2, "place", XMLfunctions.getValue(e, "name"));
OverlayItem item = new OverlayItem(point2, "", "");
listOfOverLays.add(mapOverlay2);
}
在本课程之外,我有一个课程来创建位置图标并分配位置名称:
class MapOverlay extends Overlay{
private GeoPoint pointToDraw;
private String pointerIcon;
private String locName;
public void setPointToDraw(GeoPoint point, String pointer, String locationName){
pointToDraw = point;
pointerIcon = pointer;
locName = locationName;
}
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when){
super.draw(canvas, mapView, shadow);
// convert point to pixels
Point screenPts = new Point();
mapView.getProjection().toPixels(pointToDraw, screenPts);
// add marker
if(pointerIcon == "pointer"){
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pointer);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 22, null);
}
else if(pointerIcon == "bar"){
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pointer2);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 15, null);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(20);
canvas.drawText(locName, screenPts.x, screenPts.y-20, paint);
}
return true;
}
}
我只需要点击图片'pointer2'并打开一个带有'locId'的新页面,这样我就知道点击了哪个位置。我已经在线阅读了很多关于这样做的内容,但没有任何效果。任何可以让我更接近这项工作的信息都非常感激。
答案 0 :(得分:1)
对它进行排序,但几乎必须从头开始并使用Itemized Overlay。以下是我引用的内容:http://blog.chrisblunt.com/android-map-view-double-taps-and-overlay-markers/