I seem to be having a problem with using ItemizedOverlay and
OveralyItems in it.

I can get the first overlayItem to appear on the map but not any items
after that.

Example of the code:


Java:

protected void myCalledFunction(Location myLoc) {
          // TODO Auto-generated method stub
          Markers usersMarker = new Markers(user,overview.this);
          int lat,lon;
          HttpEntity ser_resp;
          String text;

          /* Add my location to the list */
          if (myLoc != null) {


            GeoPoint myPoint = new GeoPoint(
                    (int) (myLoc.getLatitude() * 1E6),
                    (int) (myLoc.getLongitude() * 1E6));
            mc.animateTo(myPoint);
            OverlayItem itemMyself = new
OverlayItem(myPoint,getString(R.string.myPosition),getString(R.string.myPosition));
            itemMyself.setMarker(this.icon);

            usersMarker.addOverlay(itemMyself);
          }

          if (this.userid != -1) {
               Map<String, String> data = new HashMap<String,
String>();
               data.put("userid", this.userid.toString());

               try {
                    HttpResponse re = Registration.doPost("http://
www.android-town.com/getCloseUsers.php",data);

                    ser_resp = re.getEntity();
                    InputStream is = ser_resp.getContent();
                 BufferedInputStream bis = new
BufferedInputStream(is);
                 ByteArrayBuffer baf = new ByteArrayBuffer(20);

                 int current = 0;
                 while((current = bis.read()) != -1){
                     baf.append((byte)current);
                 }

                    /* Convert the Bytes read to a String. */
                 text = new String(baf.toByteArray());

                 /* If the web service returns nearby users... */
                 if (text != "") {

                    if (text.indexOf("##")>0) {
                         String[] users = text.split("##");
                         for (String user : users) {
                              String[] userData = user.split(";");
                              lat = Integer.valueOf(userData[1]);
                              lon = Integer.valueOf(userData[2]);

                              Log.e("overview", "username:
"+userData[0]+", lat: "+userData[1]+", lon: "+userData[2]);

                              GeoPoint p = new GeoPoint(
                                  (int) (lat * 1E6),
                                  (int) (lon * 1E6));
                              OverlayItem item = new
OverlayItem(p,userData[0],userData[3]);
                              item.setMarker(this.user);


                              usersMarker.addOverlay(item);

                         }
                    } else {
                         String[] userData = text.split(";");
                         lat = Integer.valueOf(userData[1]);
                         lon = Integer.valueOf(userData[2]);

                         Log.e("overview", "username: "+userData[0]+",
lat: "+userData[1]+", lon: "+userData[2]);

                         GeoPoint p = new GeoPoint(
                             (int) (lat * 1E6),
                             (int) (lon * 1E6));

                         OverlayItem item = new
OverlayItem(p,userData[0],userData[3]);
                         item.setMarker(this.user);
                         usersMarker.addOverlay(item);
                    }

                 }

               } catch (ClientProtocolException e) {
                e.printStackTrace();
                Toast.makeText(getApplicationContext(),
getString(R.string.noURLAccess), Toast.LENGTH_SHORT).show();
               } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(getApplicationContext(),
getString(R.string.noURLAccess), Toast.LENGTH_SHORT).show();
               }
          }

          /* Draw markers */
        //mc.setZoom(16);
     Log.e("overlays","items: "+String.valueOf(usersMarker.size())+",
overlays: "+String.valueOf(mapOverlays.size()));

     if (mapOverlays.size() == 0) {
          mapOverlays.add(usersMarker);
        } else {
          mapOverlays.clear();
          mapOverlays.add(usersMarker);
        }
        karta.invalidate();

     }


and my implementation of the ItemizedOverlay class:


Java:

public class Markers extends ItemizedOverlay {

     private Context ctx;

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

     public Markers(Drawable defaultMarker, Context cont) {

          super(boundCenterBottom(defaultMarker));
          this.ctx = cont;
          // TODO Auto-generated constructor stub
     }

     @Override
     protected OverlayItem createItem(int i) {
          // TODO Auto-generated method stub
          return mOverlays.get(i);
     }

     @Override
     public boolean onTap(GeoPoint p, MapView mapView) {
          // TODO Auto-generated method stub
          return super.onTap(p, mapView);
     }


     @Override
     protected boolean onTap(int index) {
          // TODO Auto-generated method stub
          Toast.makeText(this.ctx,
mOverlays.get(index).getTitle().toString()+", Latitude:
"+mOverlays.get(index).getPoint().getLatitudeE6(),
Toast.LENGTH_SHORT).show();
          return super.onTap(index);
     }

     @Override
     public int size() {
          // TODO Auto-generated method stub
          return mOverlays.size();
     }

     public void addOverlay(OverlayItem item) {
          mOverlays.add(item);
          setLastFocusedIndex(-1);
          populate();

     }

     public void clear() {
          mOverlays.clear();
          setLastFocusedIndex(-1);
          populate();
     }


}


the first marker shows up on the map but if I add any more they don't
show up? Is there a problem with the populate() method? I tried
calling it manually after adding all markers but it still didn't help.
Please, if you have any idea what could be wrong, say so.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to