0

我需要做的是,当“用户”标记进入(比方说半径 50 米)兴趣点标记之一的半径时会弹出一个对话框( showplaceDialog() )。

我该怎么做?我根本不知道该怎么做......

这就是我放置“用户”标记的方式,它随着位置的变化而移动。

@Override
public void onLocationChanged(Location location) {
    Log.d("Location", "onLocationChanged with location " + location.toString());

    if(overlayMarkerYou == null) {
        overlayMarkerYou = new MyOverlay(getResources().getDrawable(R.drawable.marker_you),mapView);
        mapView.getOverlays().add(overlayMarkerYou);
    }else{
        mapView.getOverlays().remove(overlayMarkerYou);
        mapView.invalidate();
        overlayMarkerYou = new MyOverlay(getResources().getDrawable(R.drawable.marker_you),mapView);
        mapView.getOverlays().add(overlayMarkerYou);
    }

    if (location != null) {

        mapView.invalidate();
        GeoPoint gpt = new GeoPoint(microdegrees(location.getLatitude()),microdegrees(location.getLongitude()));
        mapController.setCenter(gpt);
        overlayMarkerYou.addPoint(gpt, getString(R.string.markerYou), getString(R.string.markerYouDescription));

    }

}

这就是我为感兴趣的地方放置多个标记的方式

public void putPlacesOfInterest(){
    this.dh = new DataHelper(ShowMap.this);
    List<Pontos> list = this.dh.selectAll();
    for(Pontos p : list){
        markerPlaces.add(new OverlayItem(p.getName().toString(), Long.toString(p.getId()), new GeoPoint(p.getLat(), p.getLng())));
    }
    mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(markerPlaces, new OnItemGestureListener<OverlayItem>() {

        @Override
        public boolean onItemLongPress(int index, OverlayItem item) {
            Toast.makeText(ShowMap.this, "" + item.mTitle, Toast.LENGTH_SHORT).show();
            return true;
        }

        @Override
        public boolean onItemSingleTapUp(int index, OverlayItem item) {
            showplaceDialog(Integer.parseInt(item.mDescription),item.mTitle);
            return true;
        }

    }, mResourceProxy);

    mapView.getOverlays().add(mMyLocationOverlay);
    mapView.invalidate();
}
4

1 回答 1

1

我建议查看 LocationManager 类中可用的addProximityAlert()函数。我不确定您可以注册多少听众。

您的另一个选择是检查每个位置更新。当您的应用收到onLocationChanged()回调时,您可以循环浏览您感兴趣的地点,并检查它们是否在当前位置的 50 米范围内。为了使这更容易,您可以使用distanceTo()Location 类中的方法。

于 2012-03-17T17:56:56.017 回答