点击谷歌地图标记后,新活动无法启动

时间:2017-10-06 09:27:12

标签: java android google-maps google-maps-api-3

大家好我通过点击谷歌地图标记启动新活动有问题,当我点击它时没有弹出窗口。

以下是我使用的完整代码:

public class MainActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
@Override
public void onMapReady(final GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney and move the camera
    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            if (marker.equals(mMap)){
                Intent intent = new Intent(MainActivity.this, MarkerAdded.class);
                startActivity(intent);
            }
                return false;
        }
    });
}

1 个答案:

答案 0 :(得分:0)

Solution

mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
            @Override
            public void onInfoWindowClick(Marker marker) {
            Intent intent = new Intent(MainActivity.this, MarkerAdded.class);
            startActivity(intent);


            }
        });