I need to customized my pins/markers, I already added all the renderers and classes need it but I still don't know how to change the marker and place an image.
I followed the steps from Microsoft https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/map-pin#consuming-the-custom-map
My question is in the map implementation
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);
What do I have to add/change to place an image that I already have in the resources as the marker of this pin?
For now it takes only the image named pin.png which I as a pin, but need also sometimes to use a different image
The renderer have this:
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;
}
Selects directly Resource.Drawable.pin and maybe it's possible to call this and change it, but I don't know how to use it.
I know this is an old question but I will reply for purposes of futures queries that will coming until here. You can add your image at Assets folder and change:
BitmapDescriptorFactory.FromResource(Resource.Drawable.pin)
byBitmapDescriptorFactory.FromAsset("pin.png")