1

i am making a program in which i have to parse xml data into google map, i know how to use xml parser and bit knowledge of google mapping, here i need to fetch longitude, latitude, name and address from xml file and need to show in google map with the use of markers,please someone help me to make this one, i am placing my xml data below:-

    <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>
user1736992
  • 121
  • 1
  • 1
  • 5
  • where are you getting problem?? – maninder singh Oct 12 '12 at 06:24
  • actually maninder, i am looking for some hint codes of few lines only, because i have used xml parser but always with listview but not with google mapview, therefore i want to know what would be difference if i will use mapview instead of listview to read xml data – user1736992 Oct 12 '12 at 06:29
  • http://www.ibm.com/developerworks/opensource/library/x-android/ – Niranj Patel Oct 12 '12 at 06:42
  • xmp parsing will give you data which you are going to save in any ArrayList or any array....Right....So it does't matter on which view you are using that data. It is on you how to use that data.. – maninder singh Oct 12 '12 at 06:42

1 Answers1

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 Class --> Used to Draw a pin in map

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;
    }



}
Bucks
  • 689
  • 3
  • 11
  • 28
  • Bucks, thanks to place the code, really i got what i was looking for....can i also see some tutorial based on same requirement.. – user1736992 Oct 12 '12 at 06:46