2012-03-17 66 views
0

我需要做的是当“用户”标记进入(比方说50米半径)某个感兴趣的地方标记弹出对话框的半径时出现一个对话框(showplaceDialog())。当在标记周围50米范围内时,触发方法

我该怎么办?我根本没有线索怎么做...

这是我如何把“用户”标记,它随着位置的变化而移动。

@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(); 
} 

回答

1

我会建议考虑在的LocationManager类可用addProximityAlert()功能。我不确定你有多少听众可以注册。

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

+0

接近警报是要走的路。 – Snicolas 2012-03-17 17:59:09

+0

我应该在内部使用'addProximityAlert()'作为(Pontos p:list){'right? – silentw 2012-03-17 18:03:36

+0

我无法得到它的工作,你能给我一个例子调用'showplaceDialog()'函数吗?谢谢 – silentw 2012-03-17 19:44:40