Bing api map error on windows

Eduardo Gomez Romero 625 Reputation points
2024-09-29T13:38:30.6733333+00:00

Hello, I am using Bing maps API, to show a map, with a pin

User's image

in my tubines page, I have a button to call a pop up and add a new turbine

User's image

    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();
            }
        }
    }
}


On Android works perfectly

User's image

User's image

but on windows I get

NameValueType▶$exception{"Please set the map service token to be able to use this API. (Parameter 'MapServiceToken')"}System.ArgumentNullException.Net 8

Maui 8.0.9

Maui Community toolkit

Affected platforms windows

expected behavior: See the pin on the map on windows

    public static class MauiProgram {

        public static MauiApp CreateMauiApp() {
            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
#if WINDOWS
                .UseMauiCommunityToolkitMaps("AlKrbMWDZLkrL510ErB0LyjdmGrPsKiDayOH6V8tSBmlJYdQufZFtTnY_DEZG2xf")
#elif ANDROID || IOS
           .UseMauiMaps()
#endif
                .UseSkiaSharp()
                .UseMauiCommunityToolkit()
                .ConfigureSyncfusionCore()
                .ConfigureFonts(fonts => {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                    fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
                    fonts.AddFont("fa-solid-900.ttf", "fa");
                    fonts.AddFont("MaterialIcons-Regular.ttf", "ma");
                }).ConfigureMauiHandlers(handlers => {

                    handlers.AddHandler<BorderlessEntry, EntryHandler>();
                });

            BorderlessEntryHandler.ApplyCustomHandler();



#if DEBUG
            builder.Logging.AddDebug();
#endif
            //Services
            builder.Services.AddSingleton<HttpClient>();
            builder.Services.AddSingleton<HttpService>();
            builder.Services.AddSingleton<TurbinesService>();
            builder.Services.AddSingleton<GeoapifyService>();
            builder.Services.AddSingleton(Connectivity.Current);
            builder.Services.AddSingleton<DeviceLanguageService>();



            //Pages and ViewModels
            builder.Services.AddTransientPopup<AddTurbnePopUp, AddTurbnePopUpViewModel>();
            builder.Services.AddTransient<ChargingStationsMapPage, ChargingStationsMapPageViewModel>();
            builder.Services.AddTransient<TurbinesCollectionPage, TurbinesCollectionPageViewModel>();
            builder.Services.AddTransient<ArticleDetailsPage, ArticleDetailsPageViewModel>();


            builder.Services.AddSingleton<AppShell, AppShellViewModel>();
            builder.Services.AddSingleton<StartupPage, StartupPageViewModel>();
            builder.Services.AddSingleton<TurbineDetailPage, TurbineDetailPageViewModel>();
            builder.Services.AddSingleton<HomePage, HomePageViewModel>();
                                                                                                     
            return builder.Build();
        }
    }
}

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,514 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.