将 XML 数据解析为 Google Map Android



>我正在制作一个程序,其中我必须将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>
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;
    }

}

相关内容

  • 没有找到相关文章

最新更新