0

I am trying to show the users current location with the default blue dot in android. In my maps page I also have a layout that shows different points of interest. Im having trouble figuring out what to put for some of the variables and was wondering if someone could help me out.

This is what I'm using so far to show my location.

    Location location = locationManager
                    .getLastKnownLocation(bestProvider);
            try {

                GeoPoint myPoint2 = new GeoPoint(
                        (int) (location.getLatitude() * 1E6),
                        (int) (location.getLongitude() * 1E6));
                newoverlay.drawMyLocation(null, mapView, location, myPoint2,
                        1000);
                mapOverlays.add(newoverlay);
            } catch (NullPointerException e) {
                GeoPoint myPoint2 = new GeoPoint((int) (-1 * 1E6),
                        (int) (-1 * 1E6));
                **newoverlay.drawMyLocation(null, mapView, location, myPoint2,
                        1000);**
                mapOverlays.add(newoverlay);
            }

I'm not sure what to put as the Canvas so I placed it with null so that it would compile. I'm using the location from a location Manager and I have my geopoint from the location variable. I'm also unsure what the "when" parameter is supposed to be.

I was also wondering how the blue bubble knows to move with the person, does the picture update every x milliseconds depending on the "when" parameter?

So far the app isn't crashing, but it is also not showing the blue dot at any location. I'm sure I just need help with finding what the canvas parameter should be.

Thanks

Sean Pan
  • 493
  • 2
  • 6
  • 21

1 Answers1

1

try this way in your map activity

class CurOverlay extends Overlay {
        private GeoPoint pointToDraw;

        public void setPointToDraw(GeoPoint point) {
            pointToDraw = point;
        }

        public GeoPoint getPointToDraw() {
            return pointToDraw;
        }

        @Override
        public boolean draw(Canvas canvas, MapView curmapView, boolean shadow,
                long when) {
            super.draw(canvas, curmapView, shadow);

            // convert point to pixels
            Point screenPts = new Point();
            curmapView.getProjection().toPixels(pointToDraw, screenPts);

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

    }

i hope this will work for you.

MKJParekh
  • 34,073
  • 11
  • 87
  • 98
  • can you explain what you wrote down for me? It looks like you're telling me how to add a regular marker to a point on the screen. I'm trying to use the function drawMyLocation to show your present location in googlemaps (the blue dot that follows you as you walk) – Sean Pan Sep 01 '11 at 07:54
  • actually i dont know anything about that..but yes..if you call this in onLocationChanged() you can do that – MKJParekh Sep 01 '11 at 08:17