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 (将#修改为@)