Itemized Overlays...Not drawing a collection but refreshing????

by Scott » Fri, 23 Apr 2010 08:05:14 GMT


Sponsored Links
 'm trying to write code that draws accuracy circles around a gps
location based on a time param. I have no problem setting up the GPS,
or of calculating how to draw the circles...What's been killing me is
that the Overlays always overwrite one another...So I can never have
more than one circle...I've looked at all the examples and tutorials
online but they seem to be obsessed with putting in icons or with
Drawing from some database or array...If I understood correctly I
should be able to do itemizedoverlays and just draw as i go without
having to track each readout in an array....HELP WHAT AM I DOING
WRONG? PS This code also crashes if I touch the map now.

MY CLASS
public class HelloItemizedOverlay extends ItemizedOverlay {
private List items;
private Drawable marker;
public HelloItemizedOverlay() {
super(null);
items = new ArrayList();
}
@Override
protected OverlayItem createItem(int index) {
return (OverlayItem)items.get(index);
}
@Override
public int size() {
return items.size();
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow)
{
super.draw(canvas, mapView, shadow);
if (TempLat > 0) {
Point center = new Point();
Point left = new Point();
Point screenPts = new Point();
Projection projection = mapView.getProjection();
float[] result = new float[1];
Location.distanceBetween(TempLat, TempLon, TempLat,
TempLon +1, result);
float longitudeLineDistance = result[0];
GeoPoint leftGeo = new GeoPoint((int)(TempLat*1e6),(int)
((TempLon-TempAccy/longitudeLineDistance)*1e6));
projection.toPixels(leftGeo, left);
projection.toPixels(p, center);
int radius = center.x - left.x;
accuracyPaint.setAntiAlias(true);
accuracyPaint.setStrokeWidth(2.0f);
accuracyPaint.setColor(0xff6666ff);
accuracyPaint.setStyle(Style.STROKE);
canvas.drawCircle(center.x, center.y, radius,
accuracyPaint);
accuracyPaint.setColor(0x186666ff);
accuracyPaint.setStyle(Style.FILL);
canvas.drawCircle(center.x, center.y, radius,
accuracyPaint);
}
}
public void addItem(OverlayItem item) {
items.add(item);
populate();
}
}

MY ONCREATE INITIALIZATION CALL

super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.myGMap);
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();
mapView.setSatellite(true);
zoomLayout.addView(zoomView,
new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
mc = mapView.getController();
mc.setZoom(1;
accuracyPaint = new Paint();
overlay = new HelloItemizedOverlay();
......

MY ONLOCATIONCHANGED EVENT

public void onLocationChanged(Location location) {
MSGSTXT.setText("Location Found...");
TempTime = location.getTime();
TempLat = location.getLatitude();
TempLon = location.getLongitude();
TempAccy = location.getAccuracy();
TempSpeed = location.getSpeed();
TempBear = location.getBearing();
TempAlt = location.getAltitude();
p = new GeoPoint(
(int) (TempLat * 1E6),
(int



Other Threads

1. Soft keypad doesn't appear if EditText.setOnClickListener() is set?

Hi,

I have an EditText. If I set an OnClickListener for it, the ime keypad
doesn't appear when I click it (using the trackball on the G1):

  EditText edit = new EditText(context);
  edit.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
          // ime keypad won't appear when this is set and clicked.
      }
  });

if I don't set the click listener, the keypad will appear when
clicked. Is this expected behavior, or am I doing something wrong?

Thanks

-- 

2. Global notification for user input?

Hi,

I have some background task that is lengthy, long enough that it will
see the passing of several activities. When finished, I need to prompt
the user for some input. Is there a best-practice for keeping a
'foreground' context so I can launch an alert dialog from whichever
context is currently being shown? I can do something like this:

  public class ContextReference {
      private static ContextReference mInstance;
      private Context mContext;

      public void onActivityResume(Context context) {
          mContext = context;
      }

      public void onActivityPause() {
          mContext = null;
      }

      public Context getContext() {
          return mContext;
      }
  }

then override every onResume()/onPause() pair in all activities in my
application, have them each call the corresponding methods, this
doesn't seem like a good idea though. Is there a specialized
notification class for this sort of thing?  I also tried using a
context stored at startup from getApplicationContext(), but when I try
to use it with alert builder sometime into the life of my app, it
appears to not work,

Thanks

-- 

3. saving applications state

4. how to know whether the network operator settings are set to 'select automatically' ?

5. Execute method when background task exceeds timespan

6. Advice for uploading my apps

7. Need help to find Key Performance parameters of an Android application