Load overlays list from file

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

Load overlays list from file

Postby Kr0nZ » Thu Apr 14, 2011 7:57 pm

Hi, I am trying to develop an app to list the bus stops for my local Public Transit buses on a google map map,
but i seem to be having problem loading the overlay markers locations from a text file

Heres the code i use to load a new overlay onto the mapview:
Code: Select all
public void AddOverlayItem(int intLat, int intLong, String strStop, String strType) {
    Toast.makeText(HelloGoogleMaps.this.getBaseContext(), intLat + "," + intLong + "," + strStop + "," + strType,Toast.LENGTH_SHORT).show();
   // TODO Auto-generated method stub
    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.viva);
   
    if ("YRT".equals(strType)) {
       drawable = this.getResources().getDrawable(R.drawable.yrt);
    }
   
    HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);
   
    GeoPoint point = new GeoPoint(intLat,intLong);
    OverlayItem overlayitem = new OverlayItem(point, strStop, strType);
   
    itemizedoverlay.addOverlay(overlayitem);
   
    mapOverlays.add(itemizedoverlay);

   
}


When i call the above code from a button i click from within my app all works fine, settings get saved and marker appears on screen:
Code: Select all
WriteSettings(HelloGoogleMaps.this,String.valueOf((int)(longitude*1E6)) + "<>" +
                        String.valueOf((int)(latitude*1E6)) + "<>" + etStop.getText().toString() + "<>" + "YRT");
                     AddOverlayItem((int)(latitude*1E6),(int)(longitude*1E6),etStop.getText().toString(),"YRT");


But the problem i am having is when i call the following code at the end of the onCreate method, my overlays do not appear:
Code: Select all
public void RefreshStops() {
   // Refreshes the list of bus stop's
   //Find the directory for the SD Card using the API
   //*Don't* hardcode "/sdcard"
   File sdcard = Environment.getExternalStorageDirectory();

   //Get the text file
   File file = new File(sdcard,LocFile);

   try {
       BufferedReader br = new BufferedReader(new FileReader(file));
       String line;

       while ((line = br.readLine()) != null) {
          String LineSplit[] = line.split("<>");
          AddOverlayItem(Integer.parseInt(LineSplit[0]),Integer.parseInt(LineSplit[1]),LineSplit[2], LineSplit[3]);
       }
   }
   catch (IOException e) {
       //You'll need to add proper error handling here
      Toast.makeText(HelloGoogleMaps.this.getBaseContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
   }

   
}

Contents of file being read:
longitude<>latitude<>stopnumber<>bus-service
Code: Select all
cat BusLoc2.txt
-79261518<>44006280<>2511<>YRT
-79161518<>44006280<>3243<>YRT
-79161518<>44006280<>6465<>YRT
-79161518<>44006280<>675<>YRT


the AddOverlayItem() method is being called from RefreshStops because i have put a toast in the AddOverlayItem() method for debug purposes and can see the info being passed to it correctly but they are still not appearing??????

Any one have any idea why my markers are not being added?
Thanks for any help
Kr0nZ
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Apr 14, 2011 6:49 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 4 guests