hello
i have doubts regrading the draw method of overlay. what does "shadow"
argument infer?how its value is set?in the below code
mypositionoverlay is called in whereami1 class but how the draw method
is called??

//mypositionoverlay which extends the overlay class
public class mypositionoverlay extends Overlay{
        Location location;
        public Location getLocation() {
        return location;
        }
        public void setLocation(Location location) {
        this.location = location;
        }

        private final int mRadius = 5;

        @Override
        public void draw(Canvas canvas, MapView mapView, boolean shadow) {
                Projection projection = mapView.getProjection();
                if (shadow == false) {

                // Get the current location
                Double latitude = location.getLatitude()*1E6;
                Double longitude = location.getLongitude()*1E6;
                GeoPoint geoPoint;
                geoPoint = new 
GeoPoint(latitude.intValue(),longitude.intValue());

                // Convert the location to screen pixels
                Point point = new Point();
                projection.toPixels(geoPoint, point);
                RectF oval = new RectF(point.x - mRadius, point.y - mRadius,
                point.x + mRadius, point.y + mRadius);

                // Setup the paint
                Paint paint = new Paint();
                paint.setARGB(250, 255, 0, 0);
                paint.setAntiAlias(true);
                paint.setFakeBoldText(true);
                Paint backPaint = new Paint();
                backPaint.setARGB(175, 50, 50, 50);
                backPaint.setAntiAlias(true);
                RectF backRect = new RectF(point.x + 2 + mRadius,
                point.y - 3*mRadius,
                point.x + 65, point.y + mRadius);

                // Draw the marker
                canvas.drawOval(oval, paint);
                canvas.drawRoundRect(backRect, 5, 5, backPaint);
                canvas.drawText("Here I Am", point.x + 2*mRadius, point.y, 
paint);
                }
                super.draw(canvas, mapView, shadow);
        }

        @Override
        public boolean onTap(GeoPoint point, MapView mapView) {
        return false;
        }


}

//whereami class
public class whereami1 extends MapActivity {

        private final LocationListener locationListener = new LocationListener
() {
                public void onLocationChanged(Location location) {
                updateWithNewLocation(location);
                }
                public void onProviderDisabled(String provider){
                updateWithNewLocation(null);
                }
                public void onProviderEnabled(String provider){ }
                public void onStatusChanged(String provider, int status,
                Bundle extras){ }
                };
                MapController mapController;

    @Override
    protected boolean isRouteDisplayed() {
                return false;
        }

    mypositionoverlay positionOverlay;
    @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        MapView myMapView = (MapView)findViewById(R.id.map_view);
        mapController = myMapView.getController();
        myMapView.setSatellite(true);
        myMapView.setStreetView(true);
        myMapView.displayZoomControls(true);
        mapController.setZoom(17);

        // Add the MyPositionOverlay
        positionOverlay = new mypositionoverlay();
        List<Overlay> overlays = myMapView.getOverlays();
        overlays.add(positionOverlay);

        //find location based on the criteria
        LocationManager locationManager;
                String context = Context.LOCATION_SERVICE;
                locationManager = (LocationManager)getSystemService(context);
                Criteria criteria = new Criteria();
                criteria.setAccuracy(Criteria.ACCURACY_FINE);
                criteria.setAltitudeRequired(false);
                criteria.setBearingRequired(false);
                criteria.setCostAllowed(true);
                criteria.setPowerRequirement(Criteria.POWER_LOW);
                String provider = locationManager.getBestProvider(criteria, 
true);
                Location location = 
locationManager.getLastKnownLocation(provider);
                updateWithNewLocation(location);
                locationManager.requestLocationUpdates(provider, 2000, 10,
                locationListener);
    }

    //location is updated to the overlay
    private void updateWithNewLocation(Location location)
        {
                String latLongString;
                TextView myLocationText;

                String addressString = "No address found";

                if (location != null) {
                // Update my location marker
                positionOverlay.setLocation(location);

                // Update the map location.
                Double geoLat = location.getLatitude()*1E6;
                Double geoLng = location.getLongitude()*1E6;
                GeoPoint point = new GeoPoint(geoLat.intValue(),
                geoLng.intValue());
                mapController.animateTo(point);
                double lat = location.getLatitude();
                double lng = location.getLongitude();
                latLongString = "Lat:" + lat + "\nLong:" + lng;
                double latitude = location.getLatitude();
                double longitude = location.getLongitude();
                Geocoder gc = new Geocoder(this, Locale.getDefault());
                try {
                List<Address> addresses = gc.getFromLocation(latitude, 
longitude,
1);
                StringBuilder sb = new StringBuilder();
                if (addresses.size() > 0) {
                Address address = addresses.get(0);
                for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
                sb.append(address.getAddressLine(i)).append("\n");
                sb.append(address.getLocality()).append("\n");
                sb.append(address.getPostalCode()).append("\n");
                sb.append(address.getCountryName());
                }
                addressString = sb.toString();
                } catch (IOException e) {}
                } else {
                latLongString = "No location found";
                }
                myLocationText = (TextView)findViewById(R.id.myLocationText);
                myLocationText.setText("Your Current Position is:\n" +
                addressString + "\n" + latLongString);
                }




}
-- 
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

Reply via email to