Why is the marker window not displayed?

I was stuck, I could not understand why the information window does not appear when I click on the map marker. I read the Android developer site, and I need to add a marker and give them a name, fragment, etc. But the result is nothing.

public class ClubMapActivity extends DefaultActivity implements GoogleMap.OnMarkerClickListener { private GoogleMap mMap; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.clubmap); Bundle bundle = getIntent().getExtras(); double lat = bundle.getDouble("latitude"); double lng = bundle.getDouble("longitude"); mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); mMap.addMarker(new MarkerOptions() .position(new LatLng(lat, lng)) .title(bundle.getString("clubNmae")).snippet("AAA")); animateCameraTo(lat, lng); CameraUpdate zoom=CameraUpdateFactory.zoomTo(20); mMap.animateCamera(zoom); } public void animateCameraTo(final double lat, final double lng) { CameraUpdate center= CameraUpdateFactory.newLatLng(new LatLng(lat, lng)); CameraUpdate zoom=CameraUpdateFactory.zoomTo(18); mMap.moveCamera(center); mMap.animateCamera(zoom); } @Override public boolean onMarkerClick(Marker marker) { if(marker.isInfoWindowShown()) { marker.hideInfoWindow(); } else { marker.showInfoWindow(); } return true; } } 
+8
source share
6 answers

By default, the info window is displayed when the user marks the marker, if the marker has a set of headers.

Make sure your .title(bundle.getString("clubNmae") returns a non-zero value, otherwise you won’t be able to see the info window when you click the marker.

+16
source

It doesn't look like you are calling setOnMarkerClickListener.

https://developers.google.com/maps/documentation/android/marker

+1
source

Adding the answer to @ fish40 above: the title should be not only NotNull, but also NotEmpty, that is, even if you pass "as marker token", the information window will not appear.

+1
source

Try this code, it worked for me ....

Xml file

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/showTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/black" android:textSize="20sp" android:textStyle="bold" android:hint="Current Location" /> <TextView android:id="@+id/showLat" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="Latitude"/> <TextView android:id="@+id/showLong" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="Longitued"/> </LinearLayout> </LinearLayout> 

JAVA CODE

  if(mMap !=null) { mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() { @Override public View getInfoWindow(Marker marker) { return null; } @Override public View getInfoContents(Marker marker) { View v = getLayoutInflater().inflate(R.layout.info_window,null); TextView showTitle = (TextView) v.findViewById(R.id.showSnappest); TextView showLat = (TextView) v.findViewById(R.id.showLat); TextView showLong = (TextView) v.findViewById(R.id.showLong); LatLng latLng = marker.getPosition(); showTitle.setText(marker.getTitle()); showLat.setText("Latitude:"+latLng.latitude); showLong.setText("Longitude:"+latLng.longitude); return v; } }); } 
0
source

I had another case of this, keep in mind that if you call GoogleMap.clear (), all adapters installed in setInfoWindowAdapter will disappear. You need to install them again after calling clear

0
source

Use like this:

 MarkerOptions options = new MarkerOptions(); Marker marker = options.addMarker(new LatLng(lat,lng)).title("Title"); marker.showInfoWindow(); 

showInfoWindow() is available in the Marker object, not in the MarkerOptions object.

0
source

Source: https://habr.com/ru/post/952389/


All Articles