I was speaking to the maui community toolkit, and on their end is working
I also tried my key
http://dev.virtualearth.net/REST/v1/Locations?q=1%20Microsoft%20Way,%20Redmond,%20WA&key=AgBzQYlsJtPLozd-PF0dTvW2ig_LNNTff7QfuEN2p4wWgV_hWoMtGvzl98jNkUva
and is working
Maybe I am adding something wrong
PopUp
public partial class AddTurbnePopUpViewModel(DeviceLanguageService deviceLanguageService, TurbinesService turbinesService) : ObservableObject {
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsSaveEnable))]
string? turbineName;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsSaveEnable))]
string? turbneAddress = "Calle de Américo Castro, 28050 Madrid, Spain";
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsSaveEnable))]
DateTime? turbineInstalation;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsSaveEnable))]
string? turbineFormattedDate;
[ObservableProperty]
bool isDatePickerOpen;
public bool IsSaveEnable => !string.IsNullOrEmpty(TurbineName) &&
!string.IsNullOrEmpty(TurbneAddress) &&
!string.IsNullOrEmpty(TurbineFormattedDate);
SfDateTimePicker? DateTimePicker;
CultureInfo? currentCulture;
Location? TurbineLocation;
[RelayCommand]
void OpenDatePicker(SfDateTimePicker views) {
if (views != null) {
DateTimePicker = views;
views.IsOpen = true;
}
}
[RelayCommand]
void ConfirmDate(DateTime dateTime) {
if (DateTimePicker != null) {
currentCulture = new CultureInfo(deviceLanguageService.GetDeviceLanguage());
TurbineInstalation = dateTime;
DateTimePicker.IsOpen = false;
TurbineFormattedDate = TurbineInstalation?.ToString("G", currentCulture)!;
}
}
[RelayCommand]
void Cancel(SfDateTimePicker views) {
if (views != null) {
views.IsOpen = false;
}
}
[RelayCommand]
async Task Save(Popup popup) {
if (popup != null) {
IEnumerable<Location> locations = await Geocoding.Default.GetLocationsAsync(TurbneAddress!);
Location location = locations?.FirstOrDefault()!;
if (location != null) {
TurbineLocation = location;
}
var newTurbine = new TurbinePin {
Turbine = new Turbine(deviceLanguageService) {
Id = 1,
Name = TurbineName,
Label = "Charge station",
Address = TurbneAddress,
Location = TurbineLocation,
InstalationDateTime = TurbineInstalation,
Images = null, DataCollection = null
}
};
turbinesService.AddTurbinePin(newTurbine);
Console.WriteLine($"New Turbine added. Count: {turbinesService._turbinePins.Count}");
await ExiitAnimation(popup);
}
}
[RelayCommand]
async Task Close(Popup popup) {
await ExiitAnimation(popup);
}
private static async Task ExiitAnimation(Popup popup) {
if (popup.Content is VisualElement popUpBorder) {
// Set the anchor to the center
popUpBorder.AnchorX = 0.5;
popUpBorder.AnchorY = 0.5;
await Task.WhenAll(new Task[]
{
popUpBorder.ScaleTo(0.5, 500, Easing.CubicInOut),
popUpBorder.FadeTo(0, 500, Easing.CubicInOut)
});
popup.Close();
}
}
}
The Service
namespace METROWIND.Services {
public class TurbinesService {
public ObservableCollection<TurbinePin> _turbinePins = [];
private readonly DeviceLanguageService _deviceLanguageService;
public TurbinesService(DeviceLanguageService deviceLanguageService) {
_deviceLanguageService = deviceLanguageService;
// Initialize the collection with default turbine pins
_turbinePins.Add(new TurbinePin {
Turbine = new Turbine(deviceLanguageService) {
Id = 1,
Name = "My first turbine",
Label = "Charge station",
Address = "Av. de las Américas, Guayaquil 090513, Ecuador",
Location = new Location(-2.151993, -79.886109),
InstalationDateTime = new DateTime(2024, 1, 1, 13, 00, 00),
Images = [
"charge_station.png",
"wind_turbine.png"
],
DataCollection = [
new TurbineData("Ipad", 10),
new TurbineData("Iphone", 10),
new TurbineData("MacBook", 10),
new TurbineData("Mac", 10),
new TurbineData("Others", 10)
]
},
PinClickedCommand = null // Set this dynamically later
});
}
public void AddTurbinePin(TurbinePin turbinePin) {
if (turbinePin != null) {
_turbinePins.Add(turbinePin);
}
}
public ObservableCollection<TurbinePin> GetTurbinePinsForUI(ICommand pinClickedCommand) {
var sortedPins = _turbinePins
.OrderBy(t => t.Turbine?.InstalationDateTime)
.ToList(); // Materialize the ordered collection
foreach (var pin in sortedPins) {
pin.PinClickedCommand = pinClickedCommand;
}
return new ObservableCollection<TurbinePin>(sortedPins);
}
}
}
Free (Basic) account customers can continue to use Bing Maps for Enterprise services until June 30th, 2025.