Skip to content

[Maps] [Regression from Xamarin.Forms.Maps] Changing Location on a Pin does nothing #323

@japarson

Description

@japarson

Description

Changing the Location property on a Microsoft.Maui.Controls.Maps.Pin does not change the location of the Pin on the map.

Steps to Reproduce

  1. Create a map.
  2. Add a pin at a location.
  3. Change the location of the pin: pin. Location = something;
  4. Observe that the pin does not change its location on the map.

Possible Fix

I believe the reason this doesn't work is this line:

https://github.com/dotnet/maui/blob/main/src/Core/maps/src/Handlers/MapPin/MapPinHandler.Android.cs#L14

		public static void MapLocation(IMapPinHandler handler, IMapPin mapPin)
		{
			if (mapPin.Location != null)
				handler.PlatformView.SetPosition(new LatLng(mapPin.Location.Latitude, mapPin.Location.Longitude));
		}

The handler maintains a MarkerOptions as its PlatformView and loses track of the Marker instance created in the MapHandler. So updating the Pin's Location property updates the MarkerOptions, which has already been used to create the Marker and is therefore no longer useful. The handler should keep track of the created Marker (which is present in a private list on the MapHandler) and update its Position property directly.

Checklist
  • Modify src/Core/maps/src/Handlers/MapPin/MapPinHandler.Android.csbf77731 Edit
  • Running GitHub Actions for src/Core/maps/src/Handlers/MapPin/MapPinHandler.Android.csEdit
  • Modify src/Compatibility/Maps/src/Android/MapRenderer.csEdit
  • Running GitHub Actions for src/Compatibility/Maps/src/Android/MapRenderer.csEdit

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions