using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using Syncfusion.SfMaps.XForms; using Xamarin.Essentials; using Xamarin.Forms; using Xamarin.Forms.Xaml; namespace PRS.Mobile { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class DeliveryEditMapView { private string? _currentaddress; private Location? _currentlocation; public DeliveryEditMapView() { InitializeComponent(); } public override void Refresh() { NoMap.IsVisible = true; Map.IsVisible = false; if (ViewModel == null) return; var address = $"{ViewModel.Item.Street} {ViewModel.Item.City} {ViewModel.Item.PostCode}".Trim() .Replace(" ", " "); if (string.Equals(address, _currentaddress)) { UpdateMap(_currentlocation); return; } Task.Run(async () => { var locations = await Geocoding.GetLocationsAsync(address); _currentaddress = address; _currentlocation = locations.FirstOrDefault(); Dispatcher.BeginInvokeOnMainThread(() => UpdateMap(_currentlocation)); }); } private void UpdateMap(Location? location) { if (location == null) return; NoMap.IsVisible = false; Map.IsVisible = true; if (Device.RuntimePlatform.Equals(Device.iOS)) { Layer.MarkerSettings.MarkerIcon = MapMarkerIcon.Circle; Layer.MarkerSettings.IconColor = Color.DarkBlue; Layer.MarkerSettings.IconSize = 15; } else { Layer.MarkerSettings.MarkerIcon = MapMarkerIcon.Image; Layer.MarkerSettings.ImageSource = "mapmarker"; Layer.MarkerSettings.IconSize = 35; } Layer.MarkerSettings.FontAttributes = FontAttributes.Bold; Layer.MarkerSettings.LabelSize = 20; Layer.MarkerSettings.LabelColor = Color.DarkBlue; MapMarker marker = new MapMarker(); marker.Label = ""; marker.Latitude = location.Latitude.ToString(CultureInfo.InvariantCulture); marker.Longitude = location.Longitude.ToString(CultureInfo.InvariantCulture); Layer.Markers.Add(marker); Layer.GeoCoordinates = new Point(location.Latitude, location.Longitude); //ViewModel.Coordinates; Map.ZoomLevel = 14; } } }