PlacePickerExt 1.0.0-beta.3

.NET Standard 2.0
This is a prerelease version of PlacePickerExt.
NuGet\Install-Package PlacePickerExt -Version 1.0.0-beta.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
dotnet add package PlacePickerExt --version 1.0.0-beta.3
<PackageReference Include="PlacePickerExt" Version="1.0.0-beta.3">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PlacePickerExt --version 1.0.0-beta.3
#r "nuget: PlacePickerExt, 1.0.0-beta.3"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install PlacePickerExt as a Cake Addin
#addin nuget:?package=PlacePickerExt&version=1.0.0-beta.3&prerelease

// Install PlacePickerExt as a Cake Tool
#tool nuget:?package=PlacePickerExt&version=1.0.0-beta.3&prerelease

PlacePicker for Xamarin Forms

Place Picker is a simple cross-platform plugin which allows to pick a location and get location address from Google Maps with the help of Xamarin Essentials Geolocation & Geocoding.

Image

  • Location Entry shows the location address. (Cannot be edited)
  • Confirm Location → returns the location response.
  • Cancel → stops the operation and pops the view.

Supported Platforms

Follow Minimum support versions required for Xamarin Essentials & Permissions Plugin.

  • iOS
  • Android

Installation

Permission & Setup Information

These steps must be implemented for usage of Xamarin Forms Google Maps & Xamarin Essentials Geolocation.

Android

  • Open the AssemblyInfo.cs file under the Properties and add :
[assembly: UsesPermission(Android.Manifest.Permission.AccessCoarseLocation)]
[assembly: UsesPermission(Android.Manifest.Permission.AccessFineLocation)]
[assembly: UsesFeature("android.hardware.location", Required = false)]
[assembly: UsesFeature("android.hardware.location.gps", Required = false)]
[assembly: UsesFeature("android.hardware.location.network", Required = false)]
  • Open MainActivity.cs file, initialise the following inside the OnCreate method :
   Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle);
   Xamarin.FormsGoogleMaps.Init(this, bundle);
   Xamarin.Essentials.Platform.Init(this, bundle);
  • To use the Google Maps on Android you must generate an API key and add it to your Android project. Open AndroidManifest.xml file, and update the following in application tag

    <application>
      <meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR-API-KEY-HERE" />
      <uses-library android:name="org.apache.http.legacy" android:required="false" />
    </application>
    

iOS

  • Your app's Info.plist must contain the NSLocationWhenInUseUsageDescription key in order to access the device’s location.

Open the plist editor and add the Privacy - Location When In Use Usage Description property and fill in a value to display to the user.

Or manually edit the file and add the following :

<key>NSLocationAlwaysUsageDescription</key>
<string>Can we use your location at all times?</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Can we use your location when your app is being used?</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Can we use your location at all times?</string>
  • Open AppDelegate.cs file, and initialise :
Xamarin.FormsGoogleMaps.Init("YOUR-API-KEY-HERE");

Additional Setup

Please do make sure to exclude/ignore PlacePicker assembly from iOS & Android Linker.

  • iOS → --linkskip=PlacePicker
  • Android → PlacePicker;

Usage

  • You can set the map pin icon as follows :
LocationPicker.PinImage = "pin.png";

Make sure to add the required image resource file to corresponsing iOS & Android Projects.

  • Get Location call
var place = await LocationPicker.SelectPlace();
if (place?.Data != null)
{
   // Do the necessary code
}

The Result class :

public class BaseModel<Place>
{
    public Place Data { get; set; }

    public Status Status { get; set; }
}

Place model :

public class Place
{
    public Location Location { get; set; }
    public Placemark Placemark { get; set; }
    public string LocationAddress { get; set; }
}

Status model :

public enum Status
  {
      Success,
      Failed,
      Denied,
      Disabled,
      FeatureNotEnabled,
      NoInternet,
      Timeout,
      FeatureNotSupported,
      PermissionException,
      NSErrorException,
      Unknown
  }

Note : - The Response Status is based on location permissions & exceptions returned by the essentials plugin, you may do the action or show alerts as required.

The Response Status gives Success and returns the location data, only if locations permissions are enabled and can be accessed by the app.

DISCLAIMER

This is a fork of https://github.com/fantacode/PlacePicker

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-beta.3 90 8/25/2021
1.0.0-beta.2 74 8/25/2021
1.0.0-beta.1 79 8/25/2021
1.0.0-beta 90 8/25/2021