Android 如何将OnInfo WindowClick与标记数组一起使用?

Android 如何将OnInfo WindowClick与标记数组一起使用?,android,google-maps-markers,google-maps-android-api-2,Android,Google Maps Markers,Google Maps Android Api 2,我有一张有很多标记的地图。单击“标记”时,将显示包含信息的小窗口。当你点击它时,我想调用片段。我发现我应该在InfoWindowClick上使用onInfo,但有点不对劲。我无法得到任何值 public class Map extends Activity implements OnInfoWindowClickListener{ static final LatLng xxx = new LatLng(70.000, 70,22); static String[] stree

我有一张有很多标记的地图。单击“标记”时,将显示包含信息的小窗口。当你点击它时,我想调用片段。我发现我应该在InfoWindowClick上使用
onInfo,但有点不对劲。我无法得到任何值

public class Map extends Activity implements OnInfoWindowClickListener{

    static final LatLng xxx = new LatLng(70.000, 70,22);
    static String[] streets;
    static String[] artist;
    Coordinate cor = new Coordinate();

    private GoogleMap googleMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_layout);

        try {
            initilizeMap();
        } catch (Exception e) {
            e.printStackTrace();
        }

        Resources res = this.getResources();
        artist = res.getStringArray(R.array.authors_nicks);
        streets = res.getStringArray(R.array.streets);

        for (int i = 0; i < cor.coordinatesVale.size(); i++) {
            Marker m = googleMap.addMarker(new MarkerOptions()
                    .position(cor.coordinatesVale.get(i))
                    .title(artist[i])
                    .snippet(streets[i])
                    .icon(BitmapDescriptorFactory
                            .fromResource(R.drawable.marker)));
                    m.getId();
        }

        googleMap.setMyLocationEnabled(true);

        googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(xxx, 12));
        googleMap.animateCamera(CameraUpdateFactory.zoomTo(12), 2000, null);

    }


@Override
        public void onInfoWindowClick(Marker marker) {
         String id = marker.getId();
         Intent i = new Intent(getApplicationContext(), MainActivity.class);
         i.putExtra("dsdsd", 3);
         startActivity(i);
         Log.i("dddd", id);  /// CAN't see
     }

    private void initilizeMap() {
        if (googleMap == null) {
            googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.map)).getMap();

            if (googleMap == null) {
                Toast.makeText(getApplicationContext(),
                        "Unable to create maps", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        initilizeMap();
    }
}
公共类映射扩展活动在InfoWindowClickListener上实现{
静态最终车床xxx=新车床(70.000,70,22);
静态字符串[]街道;
静态字符串[]艺术家;
坐标cor=新坐标();
私人谷歌地图谷歌地图;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.map\u布局);
试一试{
initilizeMap();
}捕获(例外e){
e、 printStackTrace();
}
Resources res=this.getResources();
艺术家=res.getStringArray(R.array.authors\u nicks);
streets=res.getStringArray(R.array.streets);
对于(int i=0;i

我找到了一些,但我不知道我做错了什么,在你的
initializeMap()
函数中,在你使用
getMap()
之后,把下面的代码放在那里。使用此方法,您不需要调用
实现OnInfo WindowClickListener
,但两种方法的工作方式都相同

if (googleMap != null) {

    // More info: https://developers.google.com/maps/documentation/android/infowindows
    mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {
            // Determine what marker is clicked by using the argument passed in
            // for example, marker.getTitle() or marker.getSnippet().
            // Code here for navigating to fragment activity.
        }
    });
}
上面的代码允许您在用户单击信息窗口时执行某些操作

为了首先显示“信息”窗口,请使用以下代码段之一,您已经使用了这些代码段:

static final LatLng MELBOURNE = new LatLng(-37.81319, 144.96298);
Marker melbourne = mMap.addMarker(new MarkerOptions()
        .position(MELBOURNE)
        .title("Melbourne")
        .snippet("Population: 4,137,400"));
或者


来源:

可能我应该在onCreate中实现非标记。但我不知道;I don’我不知道该去哪里it@Serafins,你到底想做什么?阿卡,这个碎片有什么用?有两件事你可以做,这取决于你想完成什么。如果片段应该替换整个Map活动,那么您需要调用一个依次显示片段的活动。或者,可以通过编程方式添加显示片段的视图,将片段添加到当前地图活动中。从标记窗口,我想用这个id调用片段
Marker melbourne = mMap.addMarker(new MarkerOptions()
        .position(MELBOURNE)
        .title("Melbourne"));
melbourne.showInfoWindow();