Android Google Map v2 - 点击标记infoWindow时启动活动

时间:2013-05-21 19:26:15

标签: android google-maps android-activity google-maps-markers infowindow

我看到人们在这项具体任务中遇到很多困难,我也需要帮助。

我已使用Google提供的默认代码在地图上成功创建了标记。但现在我希望能够点击“InfoWindow”打开一个新活动,以便我可以添加更多信息。

有谁知道最好的方法吗?

如果你能回答这个 ,请提供一些代码或示例。 任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:56)

将此添加到您的代码

 Mymap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
            @Override
            public void onInfoWindowClick(Marker marker) {
               Intent intent = new Intent(MapActivity.this,OtherActivity.class);
               startActivity(intent);


            }
        });

答案 1 :(得分:1)

This method works even well with multiple markers. get the title of the marker using marker.getTitle() and Starts the activity based on which marker you clicked. 

public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        // Add a marker in Sydney and move the camera
        LatLng chennai = new LatLng(12.9671, 80.2593);
        mMap.addMarker(new MarkerOptions().position(chennai).title("Chennai"));

        LatLng perungudi = new LatLng(12.97, 80.25);
        mMap.addMarker(new MarkerOptions().position(perungudi).title("Perungudi"));

        LatLng pallikarnai = new LatLng(12.9377, 80.2154);
        mMap.addMarker(new MarkerOptions().position(pallikarnai).title("Pallikarnai"));

        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(chennai,12));
        mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {
                if (marker.getTitle().equals("Chennai")){
                    Toast.makeText(MapsActivity.this, "Clicked"+marker.getTitle(), Toast.LENGTH_SHORT).show();
                }
                return false;
            }
        });

    }