Jimmy Lee Jones
Jimmy Lee Jones

Reputation: 935

Mixed SKAnnotations customViews

I'm having trouble re-adding SKAnnotations to my map. The map displays 2 SKAnnotations of 2 cities in India: New Delhi and Chandigarh (New Delhi's layout contains a white background while Chandigarh's just a new RelativeLayout with a TextView). After a few rounds of deleting all SKAnnotations and then re-adding them, the customViews get mixed up. Here is what the map should look like:

2 Correct customView for each Annotation

And here's what might happen after a few deletions and re-addings: enter image description here

Code for adding the annotations:

public void addAnnotations() {
    SKAnnotation newDelhi = new SKAnnotation(444);
    newDelhi.setMininumZoomLevel(5);
    newDelhi.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_MARKER);
    SKAnnotationView newDelhiAnnotationView = new SKAnnotationView();
    RelativeLayout newDelhiCustomView =
            (RelativeLayout) ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
                    R.layout.annotation_layout, null, false);
    newDelhiCustomView.setTag("new delhi");
    newDelhiAnnotationView.setView(newDelhiCustomView);
    newDelhi.setAnnotationView(newDelhiAnnotationView);
    TextView newDelhiTextView = (TextView) newDelhiAnnotationView.getView().findViewById(R.id.annotation_textview);
    newDelhiTextView.setText("New Delhi");
    SKCoordinate newDelhiLocation = new SKCoordinate(77.179163, 28.619828);
    newDelhi.setLocation(newDelhiLocation);

    SKAnnotation chandigarh = new SKAnnotation(555);
    chandigarh.setMininumZoomLevel(5);
    chandigarh.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_MARKER);
    SKAnnotationView chandigahrAnnotationView= new SKAnnotationView();
    RelativeLayout chandigarhCustomView =
            new RelativeLayout(getActivity());
    chandigarhCustomView.setTag("chandigarh");
    TextView chandigarhTextView = new TextView(getActivity());    
    chandigarhTextView.setText("Chandigarh");
    chandigarhCustomView.addView(chandigarhTextView);
    chandigahrAnnotationView.setView(chandigarhCustomView);
    chandigarh.setAnnotationView(chandigahrAnnotationView);
    SKCoordinate chandigarhLocation = new SKCoordinate(76.778867,30.736094);
    chandigarh.setLocation(chandigarhLocation);

    String nd = (String)newDelhiAnnotationView.getView().getTag();
    String ch = (String)chandigahrAnnotationView.getView().getTag();

    mapView.addAnnotation(newDelhi, SKAnimationSettings.ANIMATION_NONE);
    mapView.addAnnotation(chandigarh, SKAnimationSettings.ANIMATION_NONE);
}

deleting annotations by calling: mapView.deleteAllAnnotationsAndCustomPOIs();

I'm at a comlete loss after trying to deal with this issue for about a week, TIA

Upvotes: 1

Views: 59

Answers (1)

Ando
Ando

Reputation: 11429

This was a problem in a previous version of the SDK (<= 2.5.0 I think) where the SDK did not properly manage the IDs of the annotations (and therefore at times deleting the wrong annotation).

In 2.5.1 this was fixed (shown in the release notes) by exposing the uniqueID property.

Upvotes: 2

Related Questions