Getting coordinates from XML file to map

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Getting coordinates from XML file to map

Postby Pauled » Tue Jun 14, 2011 5:31 pm

Hi all,

I have developed an app that identifies a users location, and uses an icon to display it on google maps. It also updates as they move.

With this working I have also managed to get data from a website xml file into a string. I can even count the number of results, run a for loop and extract the relative coordinates, but when I try to put these into the map the app crashes.

Here's what I have at the mo:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. MapOverlay mapOverlay = new MapOverlay();
  3. mapOverlay.setPointToDraw(point);
  4.                                
  5. List<Overlay> listOfOverLays = mapView.getOverlays();
  6. listOfOverLays.clear();
  7.                                
  8. NodeList nodes = doc.getElementsByTagName("result"); // data from XML file
  9.                                                                
  10. for (int i = 0; i < nodes.getLength(); i++) {                                                  
  11.         Element e = (Element)nodes.item(i);
  12.        
  13.         double lat = Integer.valueOf(XMLfunctions.getValue(e, "lat"));
  14.         double longi = Integer.valueOf(XMLfunctions.getValue(e, "long"));
  15.                                        
  16.         //Values of lat and longi have been tested and are correct
  17.                                        
  18.         GeoPoint point2 = new GeoPoint((int) (lat * 1E6), (int) (longi * 1E6));
  19.         OverlayItem item = new OverlayItem(point2, "", "");
  20.                                        
  21.         MapOverlay mapOverlay2 = new MapOverlay();
  22.         mapOverlay2.setPointToDraw(point2);
  23.         listOfOverLays.add(mapOverlay2);
  24.                                        
  25.         }              
  26.                            
  27.         listOfOverLays.add(mapOverlay); // this line holds the details of current location
  28.  
  29.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


If I remove all the data in the for loop the app runs fine and just displays users current location.

Please help :)
Pauled
Freshman
Freshman
 
Posts: 2
Joined: Sun Jun 12, 2011 7:16 pm

Top

Re: Getting coordinates from XML file to map

Postby abhijitphatak28 » Wed Jun 15, 2011 5:37 am

I used to work it with following code and can successfully get the overlay items drawn on the map.

Code: Select all
MyOverlay myMapOverlay = new MyOverlay(MarkerDrawable);
List<Overlay> myOverlayList = mMapView.getOverlays();
myOverlayList.add(myMapOverlay);


  private class MyOverlay extends ItemizedOverlay<OverlayItem>
    {
      private List<OverlayItem> ItemsList=new ArrayList<OverlayItem>();
      private Drawable myMarkerDrawable=null;
      
      public MyOverlay(Drawable pMarker) {
         super(marker);
         this.myMarkerDrawable=pMarker;
         
            //Your For Loop
            {
               //Get Your location values
               ItemsList.add(new OverlayItem(getPoint(logitude,latitude),"", ""));
            }
      
      
      }
   
   }
User avatar
abhijitphatak28
Senior Developer
Senior Developer
 
Posts: 102
Joined: Sat Feb 12, 2011 1:18 pm
Location: Indore

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 4 guests