1

我对 Google Maps v2 有疑问。当用户单击地图上的唯一标记时,我必须显示一个自定义对话框。但唯一发生的事情是,它将地图以标记为中心。

这是代码:

public class where extends  FragmentActivity implements OnMarkerClickListener{
  private final LatLng STARTING_POINT=new LatLng(37.5****, 14.2****);
  Marker marker;
  TextView testo;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mappa);
    GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(STARTING_POINT, 5));
    map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    //zoom che dura 2 secondi
    map.animateCamera(CameraUpdateFactory.zoomTo(19), 3000, null);
    map.setOnMarkerClickListener(this);
    marker =  map.addMarker(new MarkerOptions().position(STARTING_POINT).icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
  }
  @Override
  public boolean onMarkerClick(Marker marker) {
    if(this.marker == marker){
      AlertDialog.Builder alertadd = new AlertDialog.Builder(dovesiamo.this);
      LayoutInflater factory = LayoutInflater.from(dovesiamo.this);
      final View view = factory.inflate(R.layout.alert, null);
      alertadd.setView(view);
      alertadd.show();
    }
    return false;
  }
4

1 回答 1

2

改变

if(this.marker == marker)

if(this.marker.equals(marker))
于 2013-07-20T09:17:06.830 回答