This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Can't seem to add Markers #8718
Copy link
Copy link
Closed
Description
Platform Android
Mapbox SDK version: 4.2.2
Steps to trigger behavior
- Add a marker via
addMarkeroraddMarkers - Remove some markers
- Add a new marker
- The new marker is not shown
- Debugged the line where you can check
MapBoxMap#getMarkers().getSize(), it increases by 1 since I add a new marker
Expected behavior
- The marker should appear after
addMarker
Actual behavior
2. I added a pin and did not appear on the map. I restarted the map and my marker was actually there.
I am using the following code for adding a pin:
private void createMarker(final Recommendation recommendation)
{
if(!isVisible())
return;
mPinBitmapUtils.retrievePinBitmapAsync(getContext(), recommendation, new OnPinBitmapProcessed()
{
@Override
public void onBitmapProcess(final Pin reco, PinType pinType, Map<String, String> directories)
{
if(!isVisible())
return;
recommendation.setName(pinType.getName());
new AsyncTask<String, Void, PinMarkerOptions>()
{
@Override
protected PinMarkerOptions doInBackground(String... strings)
{
IconFactory iconFactory = IconFactory.getInstance(getContext());
Bitmap bitmap = Utils.getBitmapFromFile(getContext()
, new File(strings[0])
, (int) Utils.convertDpToPixel(48, getContext())
, (int) Utils.convertDpToPixel(48, getContext()));
Icon icon = iconFactory.fromBitmap(bitmap);
LatLng position = new LatLng();
position.setLatitude(recommendation.getLatitude());
position.setLongitude(recommendation.getLongitude());
PinMarkerOptions markerOption = new PinMarkerOptions();
markerOption.setPosition(position);
markerOption.setMetaData(recommendation.getJSON().toString());
if(icon != null)
markerOption.setIcon(icon);
return markerOption;
}
@Override
public void onPostExecute(PinMarkerOptions marker)
{
mMapboxMap.addMarker(marker);
}
}.execute(directories.get(Constants.BLUE_PIN));
}
});
}
Here is how I delete it:
private void removeFilteredMarkers()
{
for(Marker marker : mMapboxMap.getMarkers())
{
try
{
if(!(marker instanceof PinMarker))
continue;
PinMarker pinMarker = (PinMarker) marker;
String snippet = pinMarker.getMetaData();
JSONObject jsonObject = new JSONObject(snippet);
long id = jsonObject.getLong("id");
long type = (long) jsonObject.getInt("type");
if (mFilters.containsKey(type))
{
mMapboxMap.removeMarker(pinMarker);
mShownPins.remove(id);
}
}
catch (JSONException e)
{
e.printStackTrace();
}
}
}
My previous concern was closed because its a "how question" (#8704). How can this be "how question" and should directed to StackOverflow? If I did this on StackOverflow you will say I should post this on GitHub.
Thanks!
Activity
adavis commentedon Apr 14, 2017
@neonwarge04 I was experiencing a similar issue on certain devices. Once I upgraded to version
5.0.2it went away. It's worth a shot if you can upgrade. Although I did have to change a few things in several places of my code.galacticappster04 commentedon Apr 19, 2017
@adavis, I need to further test this, currently migrating from v4.2.2. Jumping from map to map, I remove unseen markers and when I return to my previous view, my markers refused to load back again. Indeed, the performance usability on v5.0.2 greatly improved.
langsmith commentedon Apr 19, 2017
@neonwarge04 , thanks for this ticket and #8704 .
I'm on the Mapbox Android team and will look into this.
Also, you might've already come across it, but I want to make sure you've seen our guide to upgrading from 4.x –> 5.x.
Thanks for your patience....
hanspeide commentedon Apr 24, 2017
Seeing the same thing.
map.clear()and then re-adding the markers works fine.galacticappster04 commentedon May 2, 2017
@hanspeide, but does it flicker?
tobrun commentedon May 3, 2017
@neonwarge04
if you are talking about MarkerView flickering, this is tracked in #8799. If you are referring to flickering of Markers when zooming in and out, this is tracked in #6762.
Related to the issue in OP, I believe not showing of these markers seems to be related to invalidation. A simple reproduce case is shown in #8833.
All issues above are added to next milestone for further investigation.
Thank you all for reaching out and chiming in.
Closing this in favor of the issues mentioned above.