0

我想做一些动作,即每当我的地理位置发生变化时,都会显示带有文本“我在这里”的对话框。

我正在使用 MyLocationOverlay 在 Google 地图的地图视图上的位置上绘制一个点。

我怎样才能做到这一点?

4

2 回答 2

1

下面是位置监听器类 -

private MyOverLay draw = new MyOverLay();

 class MyLocationListener_gps implements LocationListener {
                public void onLocationChanged(Location location) {

                    clat = location.getLatitude();
                    clon = location.getLongitude();
                                GeoPoint geoPoint = new GeoPoint((int) (clat * 1E6),
                                        (int) (clon * 1E6));
                                    mapView.getController().animateTo(geoPoint);

                                    draw = new MyOverLay(geoPoint);
                                    mapView.getOverlays().add(draw);
        }
                }

这是代码覆盖类-

class MyOverLay extends Overlay {
        private GeoPoint gp1;
        private int mRadius = 3;

        public MyOverLay() {

        }

        public MyOverLay(GeoPoint gp1) {
            this.gp1 = gp1;
        }

        @Override
        public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
                long when) {

            Projection projection = mapView.getProjection();
            if (shadow == false) {

                Paint paint = new Paint();
                paint.setAntiAlias(true);

                Point point = new Point();
                projection.toPixels(gp1, point);
                paint.setColor(Color.BLUE);

                RectF oval = new RectF(point.x - mRadius, point.y - mRadius,
                        point.x + mRadius, point.y + mRadius);

                canvas.drawOval(oval, paint);
            }

            return super.draw(canvas, mapView, shadow, when);
        }

    }

当你移动和你的坐标改变时,它会画一个蓝点。

于 2012-09-25T23:44:43.317 回答
0

覆盖 onLocationChanged 方法:

// Create an overlay to show current location
mMyLocationOverlay = new MyLocationOverlay(this, mMapView) {
  @Override
  public void onLocationChanged(android.location.Location location) {
    String text = "New coordinates: " + location.getLatitude() + ", " + location.getLatitude();
    Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT);
    toast.show();
    super.onLocationChanged(location);
  }

};
mMyLocationOverlay.runOnFirstFix(new Runnable() { public void run() {
  mMapView.getController().animateTo(mMyLocationOverlay.getMyLocation());
}});

mMapView.getOverlays().add(mMyLocationOverlay);
于 2012-09-25T13:15:37.893 回答