Skip to content

Commit

Permalink
fixed no permission crash + fix ios init
Browse files Browse the repository at this point in the history
  • Loading branch information
PavloLukianets committed May 6, 2023
1 parent ed495a8 commit a8db42b
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 76 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) themronion 2016-2022
Copyright (c) themronion 2022-2023

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 0 additions & 16 deletions lib/Maui.GoogleMaps/Handlers/MapHandler.Standard.cs

This file was deleted.

9 changes: 4 additions & 5 deletions lib/Maui.GoogleMaps/Hosting/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ namespace Maui.GoogleMaps.Hosting
{
public static class AppHostBuilderExtensions
{
public static MauiAppBuilder UseGoogleMaps(this MauiAppBuilder appBuilder
public static MauiAppBuilder UseGoogleMaps(this MauiAppBuilder appBuilder,
#if ANDROID
, Android.PlatformConfig config = null
Android.PlatformConfig config = null)
#elif IOS
, string iosApiKey, iOS.PlatformConfig config = null
string iosApiKey, iOS.PlatformConfig config = null)
#endif
)
{
appBuilder.ConfigureMauiHandlers(handlers => handlers.AddTransient(typeof(Map), h => new MapHandler()))
.ConfigureLifecycleEvents(events =>
Expand All @@ -21,7 +20,7 @@ public static MauiAppBuilder UseGoogleMaps(this MauiAppBuilder appBuilder
.OnCreate((activity, bundle) => MauiGoogleMaps.Init(activity, bundle, config)));
#elif IOS
events.AddiOS(ios => ios
.FinishedLaunching((app, options) =>
.WillFinishLaunching((app, options) =>
{
MauiGoogleMaps.Init(iosApiKey, config);
return true;
Expand Down
40 changes: 2 additions & 38 deletions lib/Maui.GoogleMaps/Maui.GoogleMaps.csproj
Original file line number Diff line number Diff line change
@@ -1,57 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net7.0-android;net7.0-ios</TargetFrameworks>
<TargetFrameworks>net7.0-android;net7.0-ios</TargetFrameworks>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>

</PropertyGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('net7.0-ios')) != true ">
<Compile Remove="Platforms\iOS\*.cs" />
<None Include="Platforms\iOS\*.cs" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('net7.0-android')) != true ">
<Compile Remove="Platforms\Android\*.cs" />
<None Include="Platforms\Android\*.cs" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('net7.0-ios')) == true OR $(TargetFramework.StartsWith('net7.0-android')) == true">
<Compile Remove="**\*.Standard.cs" />
<None Include="**\*.Standard.cs" />
<Compile Remove="**\Standard\**\*.cs" />
<None Include="**\Standard\**\*.cs" />
</ItemGroup>

<ItemGroup>
<Compile Remove="bin\**;obj\**" />
<None Remove="bin\**;obj\**" />
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="$(TargetFramework.StartsWith('net7.0-android'))">
<DefineConstants>$(DefineConstants);MONOANDROID</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net7.0-ios' ">
<DefineConstants>$(DefineConstants);IOS</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0-android'">
<PackageReference Include="Xamarin.GooglePlayServices.Maps" Version="118.1.0" />
<PackageReference Include="Xamarin.GooglePlayServices.Maps" Version="118.1.0.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0-ios'">
<PackageReference Include="Xamarin.Google.iOS.Maps" Version="6.0.1.1" />
<PackageReference Include="Xamarin.Build.Download" Version="0.11.4" />
</ItemGroup>


</Project>
15 changes: 6 additions & 9 deletions lib/Xamarin.Forms.GoogleMaps.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@
<metadata minClientVersion="2.8.3">
<id>Onion.Maui.GoogleMaps</id>
<title>Maui.GoogleMaps</title>
<version>5.0.0</version>
<version>5.0.1</version>
<releaseNotes>
# 5.0.0
# 5.0.1

- Built with net7.0
- Removed Xamarin Forms support
- Removed net7.0 target (only android and ios left)
- Reconfigure map initialization to be able to use it on the first page
- Dependencies update
</releaseNotes>
<authors>themronion</authors>
<copyright>Copyright 2016-2022</copyright>
<copyright>Copyright 2022-2023</copyright>
<license type="file">LICENSE.txt</license>
<projectUrl>https://github.com/themronion/Maui.GoogleMaps/tree/maui</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Maps library for MAUI that is optimized for Google maps.</description>
<summary>Maps library for MAUI that is optimized for Google maps</summary>
<tags>maui maps mauimaps maui.maps mauigooglemaps maui.googlemaps google googlemap</tags>
<dependencies>
<group targetFramework="net7.0">
</group>
<group targetFramework="net7.0-android">
<dependency id="Xamarin.GooglePlayServices.Maps" version="118.1.0"/>
<dependency id="Xamarin.GooglePlayServices.Maps" version="118.1.0.1"/>
</group>
<group targetFramework="net7.0-ios">
<dependency id="Xamarin.Google.iOS.Maps" version="6.0.1.1"/>
Expand All @@ -36,7 +34,6 @@
<file src="..\LICENSE.txt" target="" />

<!--Maui-->
<file src="Maui.GoogleMaps\bin\Release\net7.0\Maui.GoogleMaps.dll" target="lib\net7.0" />

This comment has been minimized.

Copy link
@jahmai-ca

jahmai-ca Jun 21, 2023

This means that even XAML files need to be in multi-targetted projects, which creates a chain knock-on effect that any XAML that indirectly references the map component also needs to be, which means that you can't put XAML into a common project between two platforms. Is this necessary?

<file src="Maui.GoogleMaps\bin\Release\net7.0-android\Maui.GoogleMaps.dll" target="lib\net7.0-android" />
<file src="Maui.GoogleMaps\bin\Release\net7.0-ios\Maui.GoogleMaps.dll" target="lib\net7.0-ios" />
</files>
Expand Down
5 changes: 0 additions & 5 deletions lib/build.bat

This file was deleted.

44 changes: 42 additions & 2 deletions sample/MauiGoogleMapSample/BasicMapPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,26 @@ public BasicMapPage()
pickerMapType.SelectedIndex = 0;

// MyLocationEnabled
switchMyLocationEnabled.Toggled += (sender, e) =>
switchMyLocationEnabled.Toggled += async (sender, e) =>
{
map.MyLocationEnabled = e.Value;
if (e.Value)
{
var status = await CheckAndRequestLocationPermission();
if (status == PermissionStatus.Granted)
{
map.MyLocationEnabled = e.Value;
await DisplayAlert("Location", "Please be aware, that GEO needs to be on to make this work", "OK");
}
else
{
await DisplayAlert("Permission", "Failed due to permission error", "OK");
switchMyLocationEnabled.IsToggled = false;
}
}
else
{
map.MyLocationEnabled = e.Value;
}
};
switchMyLocationEnabled.IsToggled = map.MyLocationEnabled;

Expand Down Expand Up @@ -164,6 +181,29 @@ public BasicMapPage()
imageSnapshot.Source = ImageSource.FromStream(() => stream);
};
}

public async Task<PermissionStatus> CheckAndRequestLocationPermission()
{
PermissionStatus status = await Permissions.CheckStatusAsync<Permissions.LocationWhenInUse>();

if (status == PermissionStatus.Granted)
return status;

if (status == PermissionStatus.Denied && DeviceInfo.Platform == DevicePlatform.iOS)
{
await DisplayAlert("Permission", "Please give location permission in settings", "OK");
return status;
}

if (Permissions.ShouldShowRationale<Permissions.LocationWhenInUse>())
{
await DisplayAlert("Permission", "Permission needed to turn on geo", "OK");
}

status = await Permissions.RequestAsync<Permissions.LocationWhenInUse>();

return status;
}
}
}

0 comments on commit a8db42b

Please sign in to comment.