Skip to content

Resolved issue with Android not placing center image #437

@GenCodeInc

Description

@GenCodeInc

For me, the Android CustomPin was centering right left, but top bottom it was anchored to the bottom, unlikes ios
Added these lines to resolve the issue in Android AddPins

---- markerOption.Anchor(0.5f, 0.5f); // Set the anchor point to the center
---- markerOption.Anchor(0.5f, 0.5f); // Set the anchor point to the center for non-custom pins as well

private void AddPins(IEnumerable<IMapPin> mapPins)
{
    if (Map is null || MauiContext is null)
    {
        return;
    }

    foreach (var pin in mapPins)
    {
        var pinHandler = pin.ToHandler(MauiContext);
        if (pinHandler is IMapPinHandler mapPinHandler)
        {
            var markerOption = mapPinHandler.PlatformView;
            if (pin is CustomPin cp)
            {
                cp.ImageSource.LoadImage(MauiContext, result =>
                {
                    if (result?.Value is BitmapDrawable { Bitmap: not null } bitmapDrawable)
                    {
                        var bitmap = GetMaximumBitmap(bitmapDrawable.Bitmap, 100, 100);
                        markerOption.SetIcon(BitmapDescriptorFactory.FromBitmap(bitmap));
                        markerOption.Anchor(0.5f, 0.5f); // Set the anchor point to the center
                    }

                    AddMarker(Map, pin, markerOption);
                });
            }
            else
            {
                markerOption.Anchor(0.5f, 0.5f); // Set the anchor point to the center for non-custom pins as well
                AddMarker(Map, pin, markerOption);
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions