I'm following the article by Xamarin that describes how to customize a pin using an image here
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;
}
I have a png image in resources/drawable. However, the map does not show any pins. I put a breakpoint in the custom renderer and it hits so I know its being called. Here is the code for the page that implements the custom map:
Xaml
<controls:CustomMap MapType="Street" x:Name="map" WidthRequest="150" IsVisible="True" HasZoomEnabled="True" HasScrollEnabled="True">
<controls:CustomMap.HeightRequest>
<OnIdiom>
<OnIdiom.Phone>
<OnPlatform
iOS="250"
Android="150" />
</OnIdiom.Phone>
</OnIdiom>
</controls:CustomMap.HeightRequest>
</controls:CustomMap>
and the code behind
var position = new Xamarin.Forms.Maps.Position(item.Latitude.Value, item.Longitude.Value); // Latitude, Longitude
var pin = new CustomPin
{
Type = PinType.Place,
Position = position,
Label = item.Name,
Address = item.AddressString
};
pin.Clicked += async (sender, e) =>
{
await Navigation.PushAsync(new RestaurantDetails(item));
};
Device.BeginInvokeOnMainThread(() =>
{
map.Pins.Add(pin);
map.CustomPins.Add(pin);
// map.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMiles(0.3)));
});