Hi, I have got the following code but my application crash. Can anyone
tell me what is wrong? Thanks!

public class GPS extends MapActivity{

        private MapController mapController;
        private MapView mapView;
        private LocationManager locationManager;
        GeoPoint p;
        int lat,lng;

         class MapOverlay extends com.google.android.maps.Overlay
            {
                @Override
                public boolean draw(Canvas canvas, MapView mapView,
                boolean shadow, long when)
                {
                    super.draw(canvas, mapView, shadow);

                    //---translate the GeoPoint to screen pixels---
                    Point screenPts = new Point();
                    mapView.getProjection().toPixels(p, screenPts);

                    //---add the marker---
                    Bitmap bmp = BitmapFactory.decodeResource(
                        getResources(), R.drawable.pin);
                    canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50,
null);
                    return true;
                }
            }


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gps);

     // create a map view
                RelativeLayout linearLayout = (RelativeLayout)
findViewById(R.id.mainlayout);
                mapView = (MapView) findViewById(R.id.mapview);
                mapView.setBuiltInZoomControls(true);
                mapView.setStreetView(true);
                mapController = mapView.getController();
                mapController.setZoom(14); // Zoon 1 is world view
                locationManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
                
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
0,
                                0, new GeoUpdateHandler());


                //---Add a location marker---
        MapOverlay mapOverlay = new MapOverlay();
        List<Overlay> listOfOverlays = mapView.getOverlays();
        listOfOverlays.clear();
        listOfOverlays.add(mapOverlay);

        mapView.invalidate();
    }

        @Override
        protected boolean isRouteDisplayed() {
                // TODO Auto-generated method stub
                return false;
        }
        public class GeoUpdateHandler implements LocationListener {

                @Override
                public void onLocationChanged(Location location) {
                        lat = (int) (location.getLatitude() * 1E6);
                        int lng = (int) (location.getLongitude() * 1E6);
                        GeoPoint point = new GeoPoint(lat, lng);
                        mapController.animateTo(point); //      
mapController.setCenter(point);
                }

                @Override
                public void onProviderDisabled(String provider) {
                }

                @Override
                public void onProviderEnabled(String provider) {
                }

                @Override
                public void onStatusChanged(String provider, int status, Bundle
extras) {
                }
        }

}

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