微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Xamarin Maps Custom Pins iOS

如何解决Xamarin Maps Custom Pins iOS

我有一个应用程序,通过Json从服务器加载特定数据。就我而言,大约有12个条目。根据实体,地图上的Pin图片应有所不同。这是我的代码

async private void GetWoodWork()
        {
.......
.......
            if(result != null)
            {
                List<ObjectData> objectDatas = JsonConvert.DeserializeObject<List<ObjectData>>(result);
                foreach (ObjectData data in objectDatas)
                {
                    string imageName;
                    string type;
                    switch(data.objectTyp)
                    {
                        case "0":
                            imageName = "fallenTree.png";
                            type = "Umgefallener Baum";
                            break;
                        case "1":
                            imageName = "illRubbish.png";
                            type = "Illegale Müllentsorgung";
                            break;
                        case "2":
                            imageName = "rubbishFull.png";
                            type = "Mülleimer voll";
                            break;
                        case "3":
                            imageName = "handsaw.png";
                            type = "Waldarbeiten";
                            break;
                        default:
                            imageName = "questionMark.png";
                            type = "Sonstiges";
                            break;
                    }

                    Position position = new Position(double.Parse(data.latitude,CultureInfo.InvariantCulture),double.Parse(data.longitude,CultureInfo.InvariantCulture));
                    var pin = gps.AddPinToMap(type,position,imageName,LocationMap,data.objectTyp);
                    //customPins.Add(pin);
                    LocationMap.CustomPins = new List<CustomPin> { pin };
                    LocationMap.Pins.Add(pin);
                }
                LocationMap.CustomPins = customPins;
            }
        }

功能正常运行。每个Pin都会获得他应有的数据。作为iOS中的MapRender,我有以下代码

protected override MKAnnotationView GetViewForAnnotation(MKMapView mapView,IMKAnnotation annotation)
        {
            MKAnnotationView annotationView = null;

            if (annotation is MKUserLocation)
                return null;

            customPins = formsMap.CustomPins;
            CustomPin customPin = customPins[0];
            if(customPins != null)
            {
                    annotationView = mapView.DequeueReusableAnnotation(customPin.Name);
                    if (annotationView == null)
                    {
                        annotationView = new CustomMKAnnotationView(annotation,customPin.Name);                   
                        annotationView.Image = UIImage.FromFile(customPin.ImageName);
                        annotationView.CalloutOffset = new CGPoint(0,0);
                        annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromFile(customPin.ImageName));
                        annotationView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.Detaildisclosure);
                        ((CustomMKAnnotationView)annotationView).Name = customPin.Name;
                        ((CustomMKAnnotationView)annotationView).Url = customPin.Url;
                    }
                    annotationView.CanShowCallout = true;                    
            }

如果我在GetViewForAnnotation的{​​{1}}中设置了一个断点,则可以看到我在那里获得了正确的信息。但是,如果加载了地图,则所有引脚都具有相同的图像。但是他们应该有不同的图片

我不知道,需要帮助。预先感谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。