0
votes

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)));
                        });
2
is BitmapDescriptorFactory.FromResource returning a value?Jason
Yes its returning a valuePatrick Goode
This is solved, didn't put the images also in the drawable-xxxx folders. UGH!Patrick Goode

2 Answers

0
votes

This is solved, didn't put the images also in the drawable-xxxx folders. UGH!

0
votes

For me, the issue was the CustomMap class which I was adding the CustomPins to did not raise the CreateMarker overridden method.

It may help someone else to know that you may see this same issue where the Pins do not appear on your CustomMap if you are adding your CustomPin objects to the CustomPin collection. I was able to fix this by adding each of them to the Pins collection as well.