Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samafshari/RedCorners.Forms.GoogleMaps
Enhanced Google Maps for Xamarin.Forms; based on Xamarin.Forms.GoogleMaps
https://github.com/samafshari/RedCorners.Forms.GoogleMaps
Last synced: 29 days ago
JSON representation
Enhanced Google Maps for Xamarin.Forms; based on Xamarin.Forms.GoogleMaps
- Host: GitHub
- URL: https://github.com/samafshari/RedCorners.Forms.GoogleMaps
- Owner: samafshari
- License: mit
- Created: 2019-05-09T17:27:29.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-07-14T12:33:49.000Z (5 months ago)
- Last Synced: 2024-09-13T13:49:44.167Z (3 months ago)
- Language: C#
- Size: 1.93 MB
- Stars: 7
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-xamarin-forms - RedCorners.Forms.GoogleMaps ★7
README
Enhanced Google Maps for Xamarin Forms. Xamarin.Forms.GoogleMaps fork.
Nuget: [https://www.nuget.org/packages/RedCorners.Forms.GoogleMaps](https://www.nuget.org/packages/RedCorners.Forms.GoogleMaps)
Documentation: [http://redcorners.com/googlemaps/](http://redcorners.com/googlemaps/)## Getting Started
`RedCorners.Forms.GoogleMaps` provides facilities to render and manage Google Maps based views on your iOS and Android Xamarin.Forms projects. In order to use `RedCorners.Forms.GoogleMaps`, you need to have the latest versions of the following packages installed:
- [`RedCorners.Forms.GoogleMaps`](https://www.nuget.org/packages/RedCorners.Forms.GoogleMaps/)
- [`RedCorners.Forms`](https://www.nuget.org/packages/RedCorners.Forms/)
- [`RedCorners`](https://www.nuget.org/packages/RedCorners/)In case you wish to access the device's location, you must ask for the required permissions prior to enabling _My Location_ on the Google Maps view. Otherwise, the app will throw an exception due to the lack of required location permissions, or will not show _My Location_. These steps are platform-dependent and described below.
### iOS Setup
In your `AppDelegate` class, or before rendering the map, you have to call the `Init` method and inject your Google Maps API key:
```c#
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
RedCorners.Forms.GoogleMapsSystem.Init("AIzaSyD8-xxxxxxxxxxxxxxxxxxxxxxxx");
// ...
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
```Based on your use case, you need to configure the `info.plist` file as follows:
```xml
NSLocationAlwaysAndWhenInUseUsageDescription
This app needs access to location to continue.
NSLocationAlwaysUsageDescription
This app needs access to location to continue.
NSLocationWhenInUseUsageDescription
This app needs access to location to continue.
```### Android Setup
You have to initialize `RedCorners.Forms.GoogleMaps` before using it. Typically you can do this in your `MainActivity.cs`:
```cs
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;base.OnCreate(savedInstanceState);
Xamarin.Forms.Forms.Init(this, savedInstanceState);
// Initialize RedCorners.Forms.GoogleMaps
RedCorners.Forms.GoogleMapsSystem.Init(this, savedInstanceState);LoadApplication(new App());
// Optional: Ask for Location Permissions
if (
(ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) != Permission.Granted) ||
(ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessCoarseLocation) != Permission.Granted))
{
ActivityCompat.RequestPermissions(this, new [] {
Manifest.Permission.AccessFineLocation,
Manifest.Permission.AccessCoarseLocation}, 1);
};
}
```Depending on your use case, you may want to request _Fine_ or _Coarse_ locations. To do this, first add the following lines in your `AndroidManifest.xml` file:
```xml
```
You should also add your API key to the manifest:
```xml
```
In case you get the `java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;` error, the following line can help:
```xml
```
The entire manifest can look like this:
```xml
```
### Showing a basic map
The first step is including the `RedCorners.Forms.GoogleMaps` namespace in your XAML file:
```xml
xmlns:map="clr-namespace:RedCorners.Forms.GoogleMaps;assembly=RedCorners.Forms.GoogleMaps"
```Afterwards, you can use `map:Map` or other variants of it such as `map:LocationPickerView` or `map:MapDrawView` to show a Google Map:
```xml
```