android-google-maps-floating-marker-titles
android-google-maps-floating-marker-titles copied to clipboard
Using MapView instead of SupportMapFragment
Sorry if this isn't the place. It is my first time commenting on such libraries. I've looked for a way of contacting you personally, but I guess this will have to do.
I'm having issues with the labels, which do NOT appear.
I'm using a MapView instead of a fragment in my xml. This is because my code is not in an activity, but in a fragment. I could be wrong in the design, but that's what I have.
What do you think is the problem? The code in java looks pretty much like you instructed, only difference I can think of is in the layout (I can also add the java code if you need).
So my layout looks like this:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.maps.MapView
android:id="@+id/agenda_map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.exlyo.gmfmt.FloatingMarkerTitlesOverlay
android:id="@+id/agenda_map_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
Hey,
The one reason I could think of if you can't see the labels appearing would be if you have not configured the source by calling floatingMarkersOverlay.setSource(googleMap); as shown in the readme... I hope this helps!
If it doesn't help, maybe you can provide a code sample so that I can take a look at it?
Hey, this indeed wasn't the case. However, I converted everything to an activity and still no luck. I'll attach the needed code, I'm guessing this is indeed something I am missing and not really a bug since it didn't work in the "classic" way as well. (Notice: in marker1 I did a test in another way to initialize a marker, you can see the intended code in marker2 and marker3)
public class AgendaActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private FloatingMarkerTitlesOverlay floatingMarkersOverlay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.agenda_activity);
// 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(GoogleMap googleMap) {
mMap = googleMap;
floatingMarkersOverlay = findViewById(R.id.agenda_map_overlay);
floatingMarkersOverlay.setSource(googleMap);
floatingMarkersOverlay.bringToFront();
long id = 0;
LatLng r1 = new LatLng(32.063785, 34.772853);
Marker marker1 = googleMap.addMarker(new
MarkerOptions().position(r1).title("Benedict").snippet(""));
// final MarkerInfo mi1 = new MarkerInfo(marker1, Color.BLUE);`
final MarkerInfo mi1 = new MarkerInfo(r1, "TEST", Color.BLUE);
floatingMarkersOverlay.addMarker(id++, mi1);
LatLng r2 = new LatLng(32.063172, 34.768373);
Marker marker2 = googleMap.addMarker(new MarkerOptions().position(r2).title("Meshek Barzilay").snippet(""));
final MarkerInfo mi2 = new MarkerInfo(marker2, Color.BLUE);
floatingMarkersOverlay.addMarker(id++, mi2);
LatLng r3 = new LatLng(32.061131, 34.763495);
Marker marker3 = googleMap.addMarker(new MarkerOptions().position(r3).title("Dallal").snippet(""));
final MarkerInfo mi3 = new MarkerInfo(marker3, Color.BLUE);
floatingMarkersOverlay.addMarker(id++, mi3);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(r1);
builder.include(r2);
builder.include(r3);
LatLngBounds bounds = builder.build();
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 100);
googleMap.animateCamera(cu);
}
}
And xml: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />
<com.exlyo.gmfmt.FloatingMarkerTitlesOverlay
android:id="@+id/agenda_map_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
The code you're showing here is so close to the sample's source code that you could simply take exactly the sample source code to start and make changes little by little to figure out where it breaks. Is the sample app working for you?
Very good idea. Unfortunately, no, it isn't working. :(
I'm not sure I understand. Are you saying that the base sample app I provided, without any modification is not working for you?
Yup, the labels are missing. The map and everything works, but there are no labels..
Can you reproduce this on the emulator? If yes, what version of Android?
So I couldn't reproduce it on an emulator on Android 9.0. And for some reason I couldn't emulate 10.0 (maybe you know why). However - I did find this: When I send the app to the background (both mine and the example) and resume - the labels appear. I am running on OnePlus7 with Android 10.
I tested on an Android 10 emulator and it's working fine there too. Have you tried the Map Marker Android app on your device to see if you have the same problem on your device?
Yes, same issue. The labels show only after minimizing and returning to the app.
So just to confirm, you downloaded this app: https://play.google.com/store/apps/details?id=com.exlyo.mapmarker On your OnePlus7 and you are noticing this bug?
Actually, it doesn't happen on the downloaded app. But i am guessing it is related to the fact we are adding markers manually. I suspect it happens only when the markers are pre-added, like in this project's example.
It does happen on this project example for me. So, again, what I see is this:
- No labels
- Send the app to background
- Resume app
- Labels appear
I don't think pre-adding the markers should change anything, the floating markers overlay repaints 60 times per second so it's probably something else. The only explanation I see would be that you have modified something in the project. Have you tried downloading a new copy of the whole project and re-build it just to be sure?
I have the same issue as @jt7785. Also using mapView, when sending the app to the background and then resuming the labels will display. Any idea on how to fix this?
Actually, it doesn't happen on the downloaded app. But i am guessing it is related to the fact we are adding markers manually. I suspect it happens only when the markers are pre-added, like in this project's example.
It does happen on this project example for me. So, again, what I see is this:
- No labels
- Send the app to background
- Resume app
- Labels appear
I am facing same issue.
I tried with the base example project again and it seems to be working. Can anyone try these steps and confirm they see the issue?
- Download a fresh copy of the sample project with 0 modifications
- Edit the API key in the manifest file (the only modification to the project files at all)
- Launch the sample app as is
- Notice the bug?
@androidseb I just tried it, the bug is indeed gone. However, I still find it strange that it is not functional with my own code with the bug. I'll try to refactor my code, to almost match your example code and will post my results/findings here.
I got the same issue. titles are not showing inside fragment