1

I have a google maps app that takes an array of points and puts them on a map. I want to add the little blue dot that moves as the user moves around. I haven't found any tutorials on how to do this. Here is an example of what I need

enter image description here

Note that the blue dot also has a blue ring that pulsates and it follows you when you start walking.

Thanks

EDIT I have found the function drawMyLocation, however I do not know where to place it. Here is my map activity and my itemized overlay (I am using a balloon itemized overlay to create the popup dialog effect)

            MapView mapView = (MapView) findViewById(R.id.mapView);
            List<Overlay> mapOverlays = mapView.getOverlays();

            for (int i = 0; i < mList.size(); i++) {
                Drawable drawable = null;
                for (int k = 0; k < ImTracking.pList.size(); k++) {
                    if (mList.get(i).getId()
                            .equals(ImTracking.pList.get(k).getid())) {
                        mList.get(i).setName(
                                ImTracking.pList.get(k).getName());
                        if (mList.get(i).getMostRecent()) {
                            drawable = Maps.this.getResources()
                                    .getDrawable(
                                            pincolorstar[ImTracking.pList
                                                    .get(k).getPosition()]);

                        } else {
                            drawable = Maps.this
                                    .getResources()
                                    .getDrawable(
                                            ImTracking.pincolors[ImTracking.pList
                                                    .get(k).getPosition()]);
                        }
                    }
                }

                HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(
                        drawable, mapView);
                GeoPoint myPoint = new GeoPoint((int) (mList.get(i)
                        .getLatitude() * 1E6), (int) (mList.get(i)
                        .getLongitude() * 1E6));
                OverlayItem overlayitem = new OverlayItem(myPoint, mList
                        .get(i).getName(), mList.get(i).getTime());
                itemizedoverlay.addOverlay(overlayitem);
                mapOverlays.add(itemizedoverlay);
            }

The above part adds all the pins to the map, the next part is where I attempt to add the mylocation overlay

MyLocationOverlay myLocationOverlay=new MyLocationOverlay(Maps.this, mapView);
                myLocationOverlay.enableMyLocation();
                mapOverlays.add(myLocationOverlay);
                MapController mc = mapView.getController();
                mc.zoomToSpan(Math.abs(maxLat - minLat),
                        Math.abs(maxLon - minLon));

                mc.animateTo(new GeoPoint((maxLat + minLat) / 2,
                        (maxLon + minLon) / 2));

            } catch (Exception e) {
                e.printStackTrace();
            }

Just adding myLocationOverlay to mapOverlays does not display the blue dot.

Sean Pan
  • 493
  • 2
  • 6
  • 21
  • Check this post: http://stackoverflow.com/questions/1513485/how-do-i-get-the-current-gps-location-programmatically-in-android There I believe you can find anything you want! – Dimitris Makris Aug 31 '11 at 19:28

1 Answers1

6

You might want to see MyLocationOverlay and see if that can fit into your requirement

Sample illustration below:


    List overlaysoverlays = mapView.getOverlays();
    // "this" refers to your activity
    MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);
    myLocationOverlay.enableMyLocation();
    overlays.add(myLocationOverlay);
momo
  • 21,233
  • 8
  • 39
  • 38
  • where can I squeeze MyLocationOverlay? In my map class I already extend MapActivity. – Sean Pan Sep 01 '11 at 06:31
  • MyLocation is an overlay that you add to the existing MapView – momo Sep 01 '11 at 08:09
  • Hi, I added this to my code and there is still no blue marker. When you use MyLocationOverlay, does it automatically call drawmyLocation? – Sean Pan Sep 01 '11 at 22:03
  • Try calling mapView.invalidate(); and see if it shows up afterward – momo Sep 01 '11 at 22:16
  • if I call mapView.invalidate() it give me an error 09-01 22:37:30.943: WARN/System.err(410): IOException processing: 26 09-01 22:37:43.274: WARN/System.err(410): java.io.IOException: Server returned: 3 – Sean Pan Sep 01 '11 at 22:38
  • I never had that problem before. Where is that stacktrace coming from? Do you have the stacktrace in order to track it? – momo Sep 01 '11 at 22:50
  • I'll post the code one more time and show exactly what I have – Sean Pan Sep 01 '11 at 22:52