2

我需要自定义我的图钉/标记,我已经添加了所有需要它的渲染器和类,但我仍然不知道如何更改标记和放置图像。

我按照微软的步骤https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/map-pin#sumption-the-custom-map

我的问题是在地图实施中

CustomPin pin = new CustomPin
        {
            Type = PinType.Place,
            Label = "Test pin",
            Position = new Position(37.79752, -122.40183)
        };
        map.CustomPins = new List<CustomPin> { pin };
        map.Pins.Add(pin);

我必须添加/更改什么才能将我已经在资源中拥有的​​图像作为此图钉的标记?

现在它只需要我作为 pin 的名为 pin.png 的图像,但有时还需要使用不同的图像

渲染器有这个:

protected override MarkerOptions CreateMarker(Pin pin)
        {
            var marker = new MarkerOptions();
            marker.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
            marker.SetTitle(pin.Label);
            marker.SetSnippet(pin.Address);
            marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.pin));
            return marker;
        }

直接选择Resource.Drawable.pin或许可以调用这个并改变它,但我不知道如何使用它。

4

1 回答 1

0

我知道这是一个老问题,但我会回答将要到这里的期货查询。您可以在 Assets 文件夹中添加图像并更改:

BitmapDescriptorFactory.FromResource(Resource.Drawable.pin)经过BitmapDescriptorFactory.FromAsset("pin.png")

于 2022-02-24T14:10:37.443 回答