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

Can't seem to add Markers #8718

Closed
galacticappster04 opened this issue Apr 12, 2017 · 6 comments
Closed

Can't seem to add Markers #8718

galacticappster04 opened this issue Apr 12, 2017 · 6 comments
Labels
Android Mapbox Maps SDK for Android support

Comments

@galacticappster04
Copy link

galacticappster04 commented Apr 12, 2017

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!

@jfirebaugh jfirebaugh added the Android Mapbox Maps SDK for Android label Apr 12, 2017
@tobrun tobrun added the support label Apr 13, 2017
@adavis
Copy link

adavis commented Apr 14, 2017

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

@galacticappster04
Copy link
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.

@langsmith
Copy link
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....

@hanspeide
Copy link

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

@galacticappster04
Copy link
Author

@hanspeide, but does it flicker?

@tobrun
Copy link
Member

tobrun commented 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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android support
Projects
None yet
Development

No branches or pull requests

6 participants