Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved issue with Android not placing center image #437

Open
GenCodeInc opened this issue Jul 10, 2024 · 0 comments
Open

Resolved issue with Android not placing center image #437

GenCodeInc opened this issue Jul 10, 2024 · 0 comments

Comments

@GenCodeInc
Copy link

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);
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant