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. Input Method and key colours

I'm attempting to produce an Input method that emulates the iPhone
keyboard.

I need to be able to adjust the colour of the keys (uses mixed key
colours) but am unable to find any documentation on setting the
background colour of a key (doesn't seem to be any properties in the
style attributes).
The closest thing I can find is setting a background image, but i
really just need to set the colour.

Does anyone have any idea how that might be done?

- Brill

-- 

2. Problem with the Spinner in ListView Activity

Hi,
I am newbie in Android Application Development. I am trying to invoke
a list in spinner can anyone tell me where I am having trouble. Please
help. Here is the code of my application

public class Spinner extends ListActivity
{
        public void onCreate(Bundle savedInstanceState)
        {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                        String[] PROJECTION = new String[]
                {
                                People._ID, People.NAME
                };
                Spinner spinner = (Spinner) findViewById(R.id.spinner);
                Cursor cur = getContentResolver().query(People.CONTENT_URI,
PROJECTION, null, null, null);
                SimpleCursorAdapter adapter2 = new
SimpleCursorAdapter(this,
                                android.R.layout.simple_spinner_item,
                                // Use a template
                                // that displays
a
                                // text view
                                cur,
                                // Give the cursor to the list adapter
                                new String[] {People.NAME},
                                // Map the NAME column in the
                                // people database to...
                                new int[] {android.R.id.text1});
                                //      The "text1" view defined in
                                // the XML template
 
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                                spinner.setAdapter(adapter2);

        }

        public class MyOnItemSelectedListener implements
OnItemSelectedListener
        {
                public void onItemSelected(AdapterView<?> parent,
                                View view, int pos, long id)
                {
                        Toast.makeText(parent.getContext(),
                        "The Person is " +
                        parent.getItemAtPosition(pos).toString(),
                        Toast.LENGTH_LONG).show();
                }
                public void onNothingSelected(AdapterView<?> parent)
                {
                        // Do nothing.
                }
        }
}

Please help..

-- 

3. Dvalve a new outsourcing booster

4. how to encode mp3 data diectly to PCM format in android

5. Activity Being Killed (onDestroy) on Orientation Change

6. Change system screen brightness

7. Secure WCF + Android