1

我正在制作一个程序,我必须在其中将 xml 数据解析为谷歌地图,我知道如何使用 xml 解析器和谷歌地图的一些知识,这里我需要从 xml 文件中获取经度、纬度、名称和地址并需要显示在使用标记的谷歌地图中,​​请有人帮我制作这个,我将我的 xml 数据放在下面:-

    <map>
      <area>
         <longitude>-97.762914</longitude> 
         <latitude>30.282165</latitude> 
         <name>Place Name 1</name> 
         <address>Place Address 1</address> 
      </area>
      <area>
        <longitude>-97.762914</longitude> 
        <latitude>31.282165</latitude> 
        <name>Place Name 3</name> 
        <address>Place Address 3</address> 
      </area>
      <area>
        <longitude>-97.762914</longitude> 
        <latitude>32.282165</latitude> 
        <name>Place Name 3</name> 
        <address>Place Address 3</address> 
      </area>
    </map>
4

1 回答 1

1
MapView mapView = new MapView(this, mapkey);
MapController mc=mapView.getController();
GeoPoint myLocation = null;
Drawable drawable = this.getResources().getDrawable(R.drawable.map_marker);
myItemizedOverlay itemizedoverlay = new myItemizedOverlay(drawable, this);
GeoPoint ppoint = new GeoPoint(platt,plngg); //platt and plngg xml parser value lattitude and Longitude
OverlayItem poverlayitem = new     OverlayItem(ppoint,bankname,name of the place);
itemizedoverlay.addOverlay(poverlayitem);
mapOverlays.add(itemizedoverlay);
myLocation = new GeoPoint(platt,plngg);
mc.animateTo(myLocation);
mapView.setBuiltInZoomControls(true);
mapView.setClickable(true);
mc.setZoom(14);
mapView.invalidate();
return mapView;

MyItemizedOverlay 类 --> 用于在地图中绘制图钉

public class myItemizedOverlay extends ItemizedOverlay<OverlayItem> {

    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    private Context mContext;


    public myItemizedOverlay(Drawable defaultMarker) {
         super(boundCenterBottom(defaultMarker));
    }

    public myItemizedOverlay(Drawable defaultMarker, Context context) {
          super(boundCenterBottom(defaultMarker));
          mContext = context;
    }

    public void addOverlay(OverlayItem overlay){
        mOverlays.add(overlay);
        populate();
    }

    @Override
    protected OverlayItem createItem(int i) {
         return mOverlays.get(i);
    }

    public void removeItem(int i){
        mOverlays.remove(i);
        populate();
    }

    @Override
    public int size() {
        return mOverlays.size();
    }

    @Override
    protected boolean onTap(int i) {
        OverlayItem item = mOverlays.get(i);
        AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
        dialog.setTitle(item.getTitle());
        dialog.setMessage(item.getSnippet());
        dialog.show();
        return true;
    }



}
于 2012-10-12T06:41:59.583 回答