开发者

How can I show my location on google maps in android

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

How can I show my location on google maps in android

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()]);

 开发者_JAVA技巧                       } 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.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜