简体   繁体   中英

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

在此处输入图片说明

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM