Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Can't seem to add Markers #8718

Closed
Closed

Description

@galacticappster04

Platform Android
Mapbox SDK version: 4.2.2

Steps to trigger behavior

  1. Add a marker via addMarker or addMarkers
  2. Remove some markers
  3. Add a new marker
  4. The new marker is not shown
  5. Debugged the line where you can check MapBoxMap#getMarkers().getSize(), it increases by 1 since I add a new marker

Expected behavior

  1. 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

  1. added
    Android
    on Apr 12, 2017
  2. adavis commented on Apr 14, 2017

    @adavis

    @neonwarge04 I was experiencing a similar issue on certain devices. Once I upgraded to version 5.0.2 it 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.

  3. galacticappster04 commented on Apr 19, 2017

    @galacticappster04
    Author

    @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.

  4. langsmith commented on Apr 19, 2017

    @langsmith
    Contributor

    @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....

  5. hanspeide commented on Apr 24, 2017

    @hanspeide

    Seeing the same thing. map.clear() and then re-adding the markers works fine.

  6. galacticappster04 commented on May 2, 2017

    @galacticappster04
    Author

    @hanspeide, but does it flicker?

  7. tobrun commented on May 3, 2017

    @tobrun
    Member

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Androidsupport

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions