I want to implement a click on the name of the marker and go to the html document that opens in the webview.

MapsActivity:

private GoogleApiClient mGoogleApiClient; private WebView mwebview; private static final int LOCATION_PERMISSION_REQUEST_CODE = 1; private boolean mPermissionDenied = false; private GoogleMap mMap; protected void onStart() { super.onStart(); if( mGoogleApiClient != null ) mGoogleApiClient.connect(); } @Override protected void onStop() { if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) { mGoogleApiClient.disconnect(); } super.onStop(); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); mapFragment.getMapAsync(this); mGoogleApiClient = new GoogleApiClient .Builder( this ) .enableAutoManage( this, 0, this ) .addApi( Places.GEO_DATA_API ) .addApi( Places.PLACE_DETECTION_API ) .addOnConnectionFailedListener( this ) .build(); } @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; mMap.setOnMyLocationButtonClickListener(this); mMap.setOnMyLocationClickListener(this); mMap.getUiSettings().setZoomControlsEnabled(true); enableMyLocation(); LatLng piligrim = new LatLng(55.92576, 37.23328); mMap.addMarker(new MarkerOptions().position(piligrim).title("Piligrim Porto")); LatLng nikola = new LatLng(54.75016, 35.60069); mMap.addMarker(new MarkerOptions().position(nikola).title("Никола-Ленивец")); LatLng abramcevo = new LatLng(56.23367, 37.96789); mMap.addMarker(new MarkerOptions().position(abramcevo).title("Усадьба Абрамцево")); LatLng muzei = new LatLng(55.19015, 40.16336); mMap.addMarker(new MarkerOptions().position(muzei).title("Музей деревянного зодчества \"Лесная Крепость\"")); LatLng vodopad = new LatLng(56.26853, 38.34439); mMap.addMarker(new MarkerOptions().position(vodopad).title("Водопад Гремячий")); LatLng vodopad2 = new LatLng(55.26853, 35.34439); mMap.addMarker(new MarkerOptions().position(vodopad2).title("Водопад Радужный")); LatLng etnomir = new LatLng(55.24281, 36.42808); mMap.addMarker(new MarkerOptions().position(etnomir).title("Этномир")); LatLng zapovednik = new LatLng(54.91070, 37.57107); mMap.addMarker(new MarkerOptions().position(zapovednik).title("Приокско-террасный заповедник")); LatLng kremel = new LatLng(55.10321, 38.75233); mMap.addMarker(new MarkerOptions().position(kremel).title("Коломенский кремль")); LatLng kremel2 = new LatLng(56.03777, 35.95708); mMap.addMarker(new MarkerOptions().position(kremel2).title("Волоколамский кремль")); mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { @Override public void onInfoWindowClick(Marker marker) { Intent intent = new Intent(MapsActivity.this, Place1.class);; intent.putExtra("intent1", 1); startActivity(intent); } }); } // TODO: Please implement GoogleApiClient.OnConnectionFailedListener to private void enableMyLocation() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { PermissionUtils.requestPermission(this, LOCATION_PERMISSION_REQUEST_CODE, Manifest.permission.ACCESS_FINE_LOCATION, true); } else if (mMap != null) { mMap.setMyLocationEnabled(true); } } @Override public boolean onMyLocationButtonClick() { Toast.makeText(this, "Моё местоположение", Toast.LENGTH_SHORT).show(); return false; } @Override public void onMyLocationClick(@NonNull Location location) { Toast.makeText(this, "Данное местоположение:\n" + location, Toast.LENGTH_LONG).show(); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode != LOCATION_PERMISSION_REQUEST_CODE) { return; } if (PermissionUtils.isPermissionGranted(permissions, grantResults, Manifest.permission.ACCESS_FINE_LOCATION)) { enableMyLocation(); } else { mPermissionDenied = true; } } @Override protected void onResumeFragments() { super.onResumeFragments(); if (mPermissionDenied) { showMissingPermissionError(); mPermissionDenied = false; } } private void showMissingPermissionError() { PermissionUtils.PermissionDeniedDialog .newInstance(true).show(getSupportFragmentManager(), "dialog"); } @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { } 

}

Class webview (Place1):

 private WebView webView; @SuppressLint("SetJavaScriptEnabled") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_place1); Intent intent1 = getIntent(); webView = (WebView) findViewById(R.id.webView); String resName ="n" + intent1.getIntExtra("title", 0); webView.loadUrl("file:///android_asset/" + resName + ".html"); } 

}

    1 answer 1

    I solved this problem like this if someone needs it for the future:

     public void onInfoWindowClick(Marker marker) { String title = marker.getTitle(); if ("Piligrim Porto".equals(title)) { Intent intent = new Intent(MapsActivity.this, Place1.class);; intent.putExtra("title", 0); startActivity(intent); } else if ("Никола-Ленивец".equals(title)) { Intent intent = new Intent(MapsActivity.this, Place1.class); intent.putExtra("title", 1); startActivity(intent); } else if ("Усадьба Абрамцево".equals(title)) { Intent intent = new Intent(MapsActivity.this, Place1.class); intent.putExtra("title", 2); startActivity(intent); } else if ("Музей деревянного зодчества \"Лесная Крепость\"".equals(title)) { Intent intent = new Intent(MapsActivity.this, Place1.class); intent.putExtra("title", 3); startActivity(intent); } else if ("Водопад Гремячий".equals(title)) { Intent intent = new Intent(MapsActivity.this, Place1.class);; intent.putExtra("title", 4); startActivity(intent); } else if ("Водопад Радужный".equals(title)) { Intent intent = new Intent(MapsActivity.this, Place1.class);; intent.putExtra("title", 5); startActivity(intent); } else if ("Этномир".equals(title)) { Intent intent = new Intent(MapsActivity.this, Place1.class);; intent.putExtra("title", 6); startActivity(intent); } else if ("Приокско-террасный заповедник".equals(title)) { Intent intent = new Intent(MapsActivity.this, Place1.class);; intent.putExtra("title", 7); startActivity(intent); } else if ("Коломенский кремль".equals(title)) { Intent intent = new Intent(MapsActivity.this, Place1.class);; intent.putExtra("title", 8); startActivity(intent); } else if ("Волоколамский кремль".equals(title)) { Intent intent = new Intent(MapsActivity.this, Place1.class);; intent.putExtra("title", 9); startActivity(intent); } else { Intent intent = new Intent(MapsActivity.this, Place1.class);; intent.putExtra("title", 4); startActivity(intent); }