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. Help Wanted!

I have been very frustrated with some fundamental issues of Android
programming. It seems to me that reliable knowledge about Android is
both scare volatile. I had imagined that Google people have a vested
interest in nurturing the developers aspiration to learn.

Alas, many of my questions have remained unanswered.

So I am looking for pointers from the good souls visiting here. What's
the best way to unblock some of my problems with Android? Where should
I post my question so that it would be more likely to get an answer.

I am even willing to hire a good soul who would assist me about an
hour a week. I am sure that just getting some of my key questions
answered will get me very far.

I live near Google in the Peninsula. If you feel like helping me and
at the same time making a bit of money, please contact me.

I really appreciate any help (even sympathy!) that anyone can  give me
over here!

best,

Ahmad

-- 

2. How to get click position in TextView?

Hello,
I need to process words on which user clicked (touched) in the
TextView. But there seems to be no way to figure out which word was
clicked.
TextView.getSelectionStart() always returns 0 even if I use
setMovementMethod(ScrollingMovementMethod.getInstance());

I have also tried EditText, but it pops up the on-screen keyboard
every time user clicks the text. And I don't want the text to be
editable anyway, and the cursor should not be visible.

Also I have tried to use setInputMethod() to use my own InputMethod
class that overrides onTouchEvent() to get the coordinates of the
click point. But than there is no way to convert the coordinates to
character position in the text.

Is there any other way?
Any advice is greatly appreciated.
Thanks a lot,
--Sergey

-- 

3. My presentation analyzing Android bootup time

4. Round Thumbs in Seek Bar

5. Google Earth Api's

6. How to write ContentProvider for content not stored in a file nor DB?

7. Starting an Activity from a callback class