Giter Site home page Giter Site logo

jamesmontemagno / geolocatorplugin Goto Github PK

View Code? Open in Web Editor NEW
291.0 35.0 159.0 1.6 MB

Geolocation plugin for Xamarin and Windows

License: MIT License

PowerShell 8.21% C# 89.30% Shell 2.48%
xamarin geolocation-plugin pcl geolocator android xamarin-forms xamarin-plugin

geolocatorplugin's Introduction

Geolocator Plugin for Xamarin and Windows

Simple cross platform plugin to get GPS location including heading, speed, and more. Additionally, you can track geolocation changes, reverse geocode, and more.

Documentation

Get started by reading through the Geolocator Plugin documentation.

For common questions and issues see the FAQ

NuGet

The Future: Xamarin.Essentials

I have been working on Plugins for Xamarin for a long time now. Through the years I have always wanted to create a single, optimized, and official package from the Xamarin team at Microsoft that could easily be consumed by any application. The time is now with Xamarin.Essentials, which offers over 50 cross-platform native APIs in a single optimized package. I worked on this new library with an amazing team of developers and I highly highly highly recommend you check it out.

I will continue to work and maintain my Plugins, but I do recommend you checkout Xamarin.Essentials to see if it is a great fit your app as it has been for all of mine!

Build

Platform Support

Version 4.X

Platform Version
Xamarin.iOS iOS 8+
Xamarin.Android API 14+
Windows 10 UWP 10+
macOS All
tvOS 10+

Feature requests Vote for a feature requests at feature

Created By: @JamesMontemagno

License

The MIT License (MIT) see License file

This is a derivative to Xamarin.Mobile's Geolocator with a cross platform API and other enhancements.

Want To Support This Project?

All I have ever asked is to be active by submitting bugs, features, and sending those pull requests down! Want to go further? Make sure to subscribe to my weekly development podcast Merge Conflict, where I talk all about awesome Xamarin goodies and you can optionally support the show by becoming a supporter on Patreon.

geolocatorplugin's People

Contributors

aurir avatar azureadvocatebit avatar cartekiwi avatar cknightdevelopment avatar davidlsharp1 avatar evan-masseau avatar ghuntley avatar jamesmontemagno avatar jasonbro avatar jixer avatar kyleupchurch avatar lucecarter avatar mkuckert avatar nbsoftware avatar nicolas-garcia avatar prashantvc avatar rohitvipin avatar thewatchfulone avatar yeah568 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

geolocatorplugin's Issues

GetPositionAsync doesn´t return a valid value in certain real Android devices.

Bug

GetPositionAsync doesn´t return a valid value in certain real Android devices.

Version Number of Plugin: 3.0.4
Device Tested On: IOS : IPhone 6, 6s, 6s Plus, 7 and 7 Plus
Android: many Samsung and Bq Aquarius

Expected Behavior

The expected behavior is that GetPositionAsync return a valid position in every device with the same location configuration.

Actual Behavior

The Bq Aquarius is not returning any data, doesn´t returns after the timeout.

I checked the location in another application and it works fine.

I checked without wifi, with wifi,...

Steps to reproduce the Behavior

 var locator = CrossGeolocator.Current;
 locator.DesiredAccuracy = 100;
 var position = await locator.GetPositionAsync(10000);

Some step more to check?

CrossGeolocator.Current.GetPositionAsync not returns after timeout

Bug

If location is turned on, but user skipped "Improve location accuracy" proposal - call to GetPositionAsync never returns a value. Method simply hangs.
My code is:
var results = await CrossGeolocator.Current.GetPositionAsync(1000);
Even if I use CancellationToken parameter to capture if geolocator cancels this call - nothing happens.

Version Number of Plugin: 3.0.4.0
Device Tested On: Nexus 5, Galaxy S5

Expected Behavior

CrossGeolocator should inform app about unsuccessful request (e.g. return null, or use method in given CancellationToken)

Actual Behavior

Method "hangs" - no result, no messages. E.g. in debugger, we simply cannot reach the code beyond this line.

Steps to reproduce the Behavior

Turn Location Off/On (popup "Improve..." will be shown")
On "Improve location accuracy" popup, press "No"
Try to receive geo-coordinates with GetPositionAsync().

Environment/framework I've used:
Win 10, MSVS2015 with Xamarin 4.0 (Xamarin.Android 6.0)

GeoLocator StopListeningAsync doesn't stop

From @RanaInside on March 27, 2016 11:10

Please take a moment to fill out the following (change to preview to check or place x in []):

This is a

  • [ x] Bug
  • Feature Request

Which plugin does this impact:

  • Battery
  • Connectivity
  • Contacts
  • DeviceInfo
  • ExternalMaps
  • [ x] Geolocator
  • Media
  • Permissions
  • Settings
  • Text To Speech
  • Vibrate
  • Other:

Version Number of Plugin:
Last Nuget Stable
Xam.Plugin.Geolocator.4.0.0-beta1

Device Tested On: iPhone 6, 6S (ios 8.2, ios9.x)
Simulator Tested On: iPhoneSimulator 8.2

Expected Behavior

expecting success from method StopListeningAsync

Actual Behavior

returns false and doesn't stop listening

Steps to reproduce the Behavior

  1. no location set in info.plist for UIBackgroundModes
  2. StartListening on PageAppear method (returns true)
  3. StopListening on PageDisappear method (returns false)

Note: I am calling it on Main thread as await; pretty sure I have tried on background thread as well.

Copied from original issue: jamesmontemagno/Xamarin.Plugins#261

GetPositionAsync does not return a position on device

Bug

Version Number of Plugin: 3.0.4
Device Tested On: OnePlus ONE E1003 Android 5.1 API 22
Simulator Tested On: -

Expected Behavior

Get position

Actual Behavior

A call of the method GetPositionAsync from my Xamarin.Forms PCL does not return a position and ends with timeout. An increase of the timeout and DesiredAccuracy, or completely remove it does not work. On the other hand, no problems on the Emulator.

Steps to reproduce the Behavior

        try
        {
            var locator = CrossGeolocator.Current;
            locator.DesiredAccuracy = 50;

            if (locator.IsGeolocationAvailable && locator.IsGeolocationEnabled)
            {
                var position = await locator.GetPositionAsync();

                Latitude.Text = position.Latitude.ToString();
                Longitude.Text = position.Longitude.ToString();
            }
        }
        catch (Exception ex)
        {
            Debug.WriteLine("Unable to get location, may need to increase timeout: " + ex);
        }

GetPositionAsync throws Exception: Position unavailable on Samsung Galaxy S5 Mini

Please fill out either the bug or feature request section and remove whatever section you are not using.

Bug

Version Number of Plugin: 3.0.4
Device Tested On: Samsung Galaxy S5 Mini
Simulator Tested On: /

Expected Behavior

Get GPS coordinates.

Actual Behavior

Throws exception with Position unavailable

Steps to reproduce the Behavior

Just call var location = await CrossGeolocator.Current.GetPositionAsync(20000);

Also happened in https://play.google.com/store/apps/details?id=com.refractored.testappforms

timeoutMilliseconds on IOS seems to depict how long the GPS will take to return

Please fill out either the bug or feature request section and remove whatever section you are not using.

Possible Bug

Running the included SAMPLE app produces some strange behaviour with the timeoutMilliseconds parameter.

On IOS Device, if I set this to 10 seconds as per sample (no code changes) then the GPS will come back eventually BUT is really slow, it wont timeout but takes approx 10+ seconds (did not time it exactly).

If I set timeoutMilliseconds to 1000 ms, then the GPS comes back (seemingly correct) after 1 second.
If I set timeoutMilliseconds to 500 ms, then the GPS comes back (seemingly correct) after 0.5 seconds?

Yes, this does not make sense, I could be doing something wrong, but I am not modifying the sample in any other way, could the async task code IOS imp be getting confused on when it is supposed to return its result?

NOTE The IOS emulator comes back instantaneously no matter the setting.
Droid (used S3) seem to use the timeout as expected.

UPDATE: After looking at the plugin code, I noticed that the accuracy of 165 of the returned IOS GPS was > then 50 default, so when setting the desired Accuracy to 200 it comes back instant :) but I would like to know why it does return the same result on the timeout above.
I "think" I can see what could be happening in the code for this to happen, will dig further.

Version Number of Plugin: 3.0.4
Device Tested On: IOS 10

Steps to reproduce the Behavior

Run the sample with various GPS timeoutMilliseconds as above.

Thanks for your help

Best
Matt

[iOS] Null reference exception from GetPositionAsync

[iOS] Null reference exception from GetPositionAsync

Version Number of Plugin: 4.0.0-beta4
Device Tested On: iPhone 5s

Expected Behavior

Position to be returned, normal GetPositionAsync behaviour.

Actual Behavior

A null reference exception is being thrown.

Steps to reproduce the Behavior

Nothing special.

readonly int _gpsSearchTimeout = 20000;
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 50;
position = await locator.GetPositionAsync(_gpsSearchTimeout);

Sorry I can't give you more useful information. That's all I get from the exception.

If it helps these are my info.plist keys:

<key>NSLocationAlwaysUsageDescription</key>
<string>Can we use your location?</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Can we use your location?</string>

Windows Phone 10 Not tracking if offline

Please fill out either the bug or feature request section and remove whatever section you are not using.

Bug

Version Number of Plugin: 3.0.4.0
Device Tested On: Lumia 930
Simulator Tested On:

Expected Behavior

Catch coordinates

Actual Behavior

When offline the exception task is canceled is thrown

Steps to reproduce the Behavior

  • device offline
  • (
    private async Task setgeo()
    {
    var locator = CrossGeolocator.Current;
    locator.DesiredAccuracy = 100; //100 is new default
    var position = await locator.GetPositionAsync(timeoutMilliseconds: 10000);
    if (position != null)
    {
    gps.data = position.Timestamp;
    gps.latitude = position.Latitude;
    gps.longitude = position.Longitude;
    }
    return gps;
    }

When device is connected works fine, if disconnected, no coordinates are returned.

Feature Request:

  • Offline position tracking.

GeoLocator - Request - Get NMEA string and Number of Satellites

From @tlhintoq on June 13, 2016 15:54

This is a

  • Feature Request

Which plugin does this impact:

  • Geolocator

Feature Request:

It would be really great if the Number of Satellites and raw NMEA string could be accessible properties just like Latitude, Longitude etc. I feel silly contemplating have to create my own dependency service for these when GeoLocator is (presumably) already grabbing this data. Not to mention worrying that two different services trying to grab the same data just smells like trouble.

Copied from original issue: jamesmontemagno/Xamarin.Plugins#330

IsGeolocationEnabled return allways true

Version Number of Plugin: 3.0.4
Device Tested On: Lumia 950 XL (UWP project)

IsGeolocationEnabled and IsGeolocationAvailable return allways True also if GPS is turned off, so i can't check if GPS is enabled or not

Please solve, thanks.

How to use the speed value

I was checking out the GeolocatorPlugin on the Android Emulator. The values of Timestamp, Latitude and Longitude just work fine except of the speed value

Expected Behavior

Receiving a speed value while chainging the GPS point.

Actual Behavior

Receiving the value 0

Steps to reproduce the Behavior

private async void GetGeolocation() {
     this.locator = CrossGeolocator.Current;
     this.locator.DesiredAccuracy = 50;
     await this.locator.StartListeningAsync(1000, 0);

     this.position = await this.locator.GetPositionAsync(timeoutMilliseconds: 1000);

     this.locator.PositionChanged += (sender, e) => {
           this.position = e.Position;

           this.Status.Text = "Position Status: " + this.position.Timestamp;
           this.Lat.Text = "Position Latitude: " + this.position.Latitude;
           this.Long.Text = "Position Longitude: " + this.position.Longitude;
           this.Speed.Text = "Speed: " + this.position.Speed + " m/s";
        };
  }

Feature Request:

How to handle the speed value correct?

MinTime in StartListeningAsync no effect in iOS

The iOS implementation of IGeoLocator does not use the parameter "minTime" in StartListeningAsync() (GeolocatorPlugin/src/Geolocator.Plugin.iOSUnified/GeolocatorImplementation.cs). The parameter is used in the Android implementation.
I have tried to set the minTime to 10,000 in the iOS simulator. I would expect this would restrict PositionChanged to be invoked with at least 10 seconds apart, but it is invoked every second.

Bug

Version Number of Plugin: 3.0.4
Simulator Tested On: iOS 10 iPad Air 2

PositionChanged Event not fired

Hi,

I am usung the latest stable version of GeoLogatorPlugin in my Xamarin.Forms PCL Project but the Changed event doesn't get fired. I have that code

 private async void OnGeoLocationStartTrackingClicked(object sender, EventArgs e)
    {
        if (CrossGeolocator.Current.IsListening)
            return;

        if (!CrossGeolocator.Current.IsGeolocationAvailable)
        {
            await DisplayAlert("GPS Start", "GPS ist auf Ihrem Gerät nicht verfügbar.", "Ok");

            return;
        }

        if (!CrossGeolocator.Current.IsGeolocationEnabled)
        {
            await DisplayAlert("GPS Start", "GPS ist auf Ihrem Gerät nicht aktiviert. Prüfen Sie die Einstellungen am Phone.", "Ok");
            return;
        }

        CrossGeolocator.Current.DesiredAccuracy = 1;
        GeoLocationStatusLabel.Text = "Getting gps";
        CrossGeolocator.Current.PositionChanged += (o, args) =>
        {
            var position = args.Position;

            GeoLocationStatusLabel.Text =
                $"Time: {position.Timestamp} \n" +
                $"Lat: {position.Latitude} \n" +
                $"Long: {position.Longitude} \n " +
                $"Altitude: {position.Altitude} \n" +
                $"Altitude Accuracy: {position.AltitudeAccuracy} \n" +
                $"Accuracy: {position.Accuracy} \n " +
                $"Heading: {position.Heading} \n " +
                $"Speed: {position.Speed}";
        };

        //minTime in msec, minDistance in meter see https://blog.xamarin.com/geolocation-for-ios-android-and-windows-made-easy/
        bool result = await CrossGeolocator.Current.StartListeningAsync(minTime:1, minDistance:1, includeHeading:true);

        if (!result)
        {
            await DisplayAlert("GPS Start", "GPS Tracking konnte nicht gestarted werden", "Ok");
            return;
        }

        StartGeoLocationInfoButton.IsEnabled = false;
        StopGeoLocationInfoButton.IsEnabled = true;
    }

Thanks for any help
Eric

Err Name Not Resolved on Maps

Please fill out either the bug or feature request section and remove whatever section you are not using.

Bug

Version Number of Plugin: 3.0.4
Device Tested On: VS Droid Emulator
Simulator Tested On: Visual Studio

I am using the location code like so....
var position = await locator.GetPositionAsync(10000);
var success = await CrossExternalMaps.Current.NavigateTo("Current", position.Latitude, position.Longitude);

But when the maps open on the simulator I get 👍

image

If I pass in a known Lat and Long like the Space Needle example, the Cross external maps works just fine. Am I missing something

Target Framework Version Issue

Good afternoon,

I have been using Geolocator plugin for a while now, but for some reason and without updating the package, it is now asking for a greater Android version (6.0), whereas my project has always been targeting 4.0.3. How can I lower its version?

Here's the error:
PathXYZ.csproj: Warning XA0105: The $(TargetFrameworkVersion) for Plugin.Geolocator.dll (v6.0) is greater than the $(TargetFrameworkVersion) for your project (v4.0.3). You need to increase the $(TargetFrameworkVersion) for your project. (XA0105) (ProjectXYZ)

Same thing happening with DeviceMotion and Permissions plugins.

I don't have any Android 6.0 at my possession and need to test the app on real devices, so using an emulator is out of the question.

Sincerely,
Luís Fernandes

Coords are different on android and iphone devices

Bug

Version Number of Plugin: 3.0.4
Device Tested On: Samsung Galaxy S5 (Android 6.0.1), iPhone 5 (iOS 9.3)

Expected Behavior

Coords of current location are the same (or approx the same) in both android and ios.

Actual Behavior

Android returns the coords -XX.1329328, -XX.885063 while in iphone the coords returned are -XX,1328481193063, -XX,8850149120623 (the values XX are the same in both cases). When I set a pin in android I can see it on another android but not an iphone device and vice versa.

Steps to reproduce the Behavior

Use geolocation to get your current location on both phones

Position position = await CrossGeolocator.Current.GetPositionAsync(30000);

Heading inconsistent between platforms

On Android, Location.Bearing is used which according to the documentation (https://developer.android.com/reference/android/location/Location.html#getBearing()):

Bearing is the horizontal direction of travel of this device, and is not related to the device orientation. It is guaranteed to be in the range (0.0, 360.0] if the device has a bearing.

But on iOS GeolocatorImplementation uses CLLocationManager's heading, which according to https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/GettingHeadings/GettingHeadings.html:

Devices with a magnetometer can report the direction in which a device is pointing, also known as its heading.

Instead of using CLLocation's Course which is defined as (https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/index.html#//apple_ref/occ/instp/CLLocation/course):

The direction in which the device is traveling.

I'm not familiar enough with windows phone to comment on its implementation.

Feature Request:

Unification between the platforms. Both Android and iOS provide GPS-based bearing (course) information. I expected an iOS geolocation api to provide the course bearing, not the magnetometer heading.

Also, in the interest of compartmentalization, shouldn't the plugin prioritize the use of the GPS-based data, and provide a means (ex. HasHeading property) for developers to determine if they need to fall back on a sensor (which could be accessed via a sensor plugin)?

Does not work on Windows 10 Mobile devices

Version Number of Plugin: 3.0.4
Device Tested On: Nokia Lumia 930 (Windows 10 Mobile upgraded)
Simulator Tested On:

The GPS location works in the Emulator, but not on a device. It may be because of the missing RequestAccessAsync call in the plugin?

https://msdn.microsoft.com/en-us/windows/uwp/maps-and-location/guidelines-and-checklist-for-detecting-location

Starting in Windows 10, call the RequestAccessAsync method before accessing the user’s location. At that time, your app must be in the foreground and RequestAccessAsync must be called from the UI thread.

Xam.Geolocator does not work on iOS 9.3

From @jj09 on April 13, 2016 21:33

Please take a moment to fill out the following (change to preview to check or place x in []):

This is a

  • Bug
  • Feature Request

Which plugin does this impact:

  • Battery
  • Connectivity
  • Contacts
  • DeviceInfo
  • ExternalMaps
  • Geolocator
  • Media
  • Permissions
  • Settings
  • Text To Speech
  • Vibrate
  • Other:

Version Number of Plugin: 4.0.0-beta2
Device Tested On: iPhone 5s (working with iOS 8.x, does not after update to 9.3.1), Apple Store (failed certification on iOS 9.3.1)
Simulator Tested On: iPhone 6S

Expected Behavior

var position = await locator.GetPositionAsync (timeoutMilliseconds: 100000); returns location

Actual Behavior

fails with System.NullReferenceException thrown inside plugin code

Steps to reproduce the Behavior

try to get location with

var position = await locator.GetPositionAsync (timeoutMilliseconds: 100000);

on iOS 9.3.x with Xam.Geolocator v4.x

Copied from original issue: jamesmontemagno/Xamarin.Plugins#277

Significant location updates don't always stop after StopListeningAsync (iOS)

From @kgerken on April 15, 2016 16:37

This is a

  • Bug
  • Feature Request

Which plugin does this impact:

  • Battery
  • Connectivity
  • Contacts
  • DeviceInfo
  • ExternalMaps
  • Geolocator
  • Media
  • Permissions
  • Settings
  • Text To Speech
  • Vibrate
  • Other:

StopListeningAsync does not always stop the location monitoring if the geolocator was started with significant location changes (SLC). SLC wakes the app periodically and even restarts it after a device reboot. In those cases, IsListening in GeolocatorImplementation might no longer be true, so StopListeningAsync immediately returns.

CLLocationManager does not seem to provide a property to check for the current listening status, yet it appears to be save to call stopMonitoringSignificantLocationChanges on CLLocationManager even when the manager is not currently monitoring. But even if the check for IsListening was removed from StopListeningAsync, we would still need to know whether we should stop the "normal" location updates or SLC, so maybe the ListenerSettings need to be passed into StopListeningAsync as well?

Copied from original issue: jamesmontemagno/Xamarin.Plugins#284

Have IsGeolocationAvailable and IsGeolocationEnabled take into account permissions

From @ferrydeboer on May 12, 2016 10:26

Please take a moment to fill out the following (change to preview to check or place x in []):

This is a

  • Feature Request

Which plugin does this impact:

  • Geolocator

Version Number of Plugin: 3.0.4
Device Tested On: Sony Xperia Z3 Compact
Simulator Tested On: -

Expected Behavior

Plugin will request permission when IsGeolocationAvailable or IsGeolocationEnabled is queried but there are no granted permissions yet.

Actual Behavior

We query both properties prior to doing a location request thus preventing a possible exception. But since these properties return false when no permissions have been granted yet our code never reaches the GetPositionAsync where the actual permission is requested.

Steps to reproduce the Behavior

Change lines 29 and 30 of GeolocatorTests.GeolocatorTests.cs to

if (CrossGeolocator.Current.IsGeolocationAvailable && CrossGeolocator.Current.IsGeolocationEnabled)
{
    var test = await CrossGeolocator.Current.GetPositionAsync();
    label.Text = "Lat: " + test.Latitude.ToString() + " Long: " + test.Longitude.ToString();
}
else
{
    label.Text = "GPS is unavailable or not enabled!";
}

Copied from original issue: jamesmontemagno/Xamarin.Plugins#300

Geolocator 4.0 Changes

From @jamesmontemagno on March 4, 2016 16:21

Breaking Changes:

  • Adjust all times to TimeSpan
  • Introduce better listening settings
  • Change IsGeolcationAvailable and IsGeoloationEnabled to Task
  • Add request permission Async
  • Remove Desired Accuracy & bundle into PositionSettings for GetPositionAsync
  • Add Activity Type

Copied from original issue: jamesmontemagno/Xamarin.Plugins#243

Issue on Ios 10

I always use this plugin to get my latitude and longitude and never had problem with that.

But now with IOS 10, I dont know why it dosnt give the latitude/longitude.. and its not asking to Active your Location on device.

is there any change with ios 10 ?
Im testing on device.
On android is working Fine.

My info.plist
NSLocationAlwaysUsageDescription
Ative sua geolocalização

My Code
var locator = CrossGeolocator.Current;
var position = await locator.GetPositionAsync(10000);

StartListeningAsync breaking on iOS.

My iOS app is breaking if I use:

if (!locator.IsListening)
                    await locator.StartListeningAsync(1000, 1);

If I remove that line everything works fine. I've added the code:

<key>UIBackgroundModes</key>
  <array>
    <string>location</string>
  </array>

to my info.plist and also set locator.AllowsBackgroundUpdates = true; but is still not working. The app just freezes! :( It took me a long time (I estimate over a week atm) to figure out this was the issue, do you have any idea on what am I doing wrong?

Bug

Version Number of Plugin: 3.0.4
Device Tested On: iPhone 6S on iOS 9.3.3 and 9.3.4

Expected Behavior

Constant location updates

Actual Behavior

App freezes

Steps to reproduce the Behavior

Create an app, use the GeoLocator plugin and call StartListeningAsync.

Thanks!

Getting rid of "isolated" GPS bad readings

@jamesmontemagno (sorry really don't know where else to contact you to ask this).

I have been using your plugin successfully on Android and iOS, but sometimes when using my app I get weird readings (which I think are a result of going close to tall buildings which affect the signal quality or precision of the GPS), showing up as "weird spikes" (isolated points) when looked at a map. Then when the signal reestablishes it starts reading everything right 👍

Looking up at the code of "MyDriving" which you gave me as a reference to run the Android Service on the background, I can't seem to find how you fixed this (if you did). I thought to use the GPS signal quality but really cant find a way to do so on Xamarin Forms. Do you know a way I can get rid of this "bad readings"?

pd: Also thought about using the compass, but not all devices have compass so it wouldn't work.. Right now I am calculating the acceleration as a magnitude and using that to eliminate some of those wrong readings but if you know a better way I would really appreciate it.

Also if you need more information please let me know!

Object not set to an instance on iOS Device

Hello, James. We are using geolocator in xamarin forms app to get location. In android - no problem. Then we test it on iOS device with iOS 10 and on GetLocationAsync() it throws exception "Object not set to an instance". What is the problem here? Thanks in advance!

Android Nougat not work GetPositionAsync()

Bug

I tested the next "locator.GetPositionAsync()" breakpoint and failed. Is it because of nougat?

Version Number of Plugin: 4.0.0-beta12
Device Tested On:
Huawei P9 Lite, Android 6: Ok
OnePlus 1, Android 7: Crash or not work

Steps to reproduce the Behavior

var locator = CrossGeolocator.Current;
var position = await locator.GetPositionAsync(); // Failed and does not show message error
pos = new Position(position.Latitude, position.Longitude);

Readme.txt

Bug

I had to set the ACCESS_COARSE_LOCATION & ACCESS_FINE_LOCATION in the Droid project file. It is not automatically added as described here:

IMPORTANT
Android:
The ACCESS_COARSE_LOCATION & ACCESS_FINE_LOCATION permissions are required, but the library will automatically add this for you.
Additionally, if your users are running Marshmallow the Plugin will automatically prompt them for runtime permissions.

Different Position.Timestamp between Android and iOS

img_1140

Bug

Different Timestamp is returned by Android devices and iOS devices.

I wrote a simple program that displays Latitude, Longitude, Altitude, Timestamp, Timestamp.LocalDateTime, Accuracy, Heading.

Like you can see in the attachment (taked at 16:20 local, 14:20 UTC time) the Android phone (Galaxy A3) shows the correct timestamp, instead on the iOS devices (iPhone 4 / iPhone 5c) a wrong timestamp is displayed (an hour back).

                LabelTime.Text = pos.Timestamp.ToString("HH:mm:ss z");
                LabelTimeLocal.Text = pos.Timestamp.LocalDateTime.ToString("HH:mm:ss z");

Version Number of Plugin: 3.0.4 (last stable)
Device Tested On: Samsung Galaxy A3 (Android 5.0.2) / iPhone 4 (iOS 9.2.1) / iPhone 5c (iOS 9.3.4)
Simulator Tested On:

TaskCanceledException when GPS times out

Bug

Version Number of Plugin: 4.0.0-beta4
Device Tested On: Nexus 9 (6.0.1), LG G3 (6.0)

Expected Behavior

I would expect the GeolocationAvailable flag to be set to false, a null location, or some exception indicating what has happened other than TaskCanceled - something like GeolocatorTimeout, or NoGeolocatorPosition.

Actual Behavior

When my device tries getting a lock with GetPositionAsync and some millisecond value, and has no GPS signal, it throws a TaskCanceledException.

Steps to reproduce the Behavior

When inside a building
Turn on high accuracy (GPS only) GPS settings
Load an app with GetPositionAsync and some millisecond parameter.
Wait that long

IsGeolocationAvailable hangs if no network connection available

Bug

Version Number of Plugin: 3.0.4
Device Tested On: Surface Pro 4 (Windows 10.0.14393)

Expected Behavior

No hang

Actual Behavior

Hangs

Steps to reproduce the Behavior

  1. set Flight mode on (no network)
  2. call IsGeolocationAvailable (first call works ok)
  3. call IsGeolocationAvailable again (second call never returns)

Possibly same issue with IsGeolocationEnabled

Heading value returns 0 in GeoLocator plugin

From @Nikygm on May 16, 2016 13:30

Please take a moment to fill out the following (change to preview to check or place x in []):

This is a

  • Bug
  • Feature Request

Which plugin does this impact:

  • Battery
  • Connectivity
  • Contacts
  • DeviceInfo
  • ExternalMaps
  • Geolocator
  • Media
  • Permissions
  • Settings
  • Text To Speech
  • Vibrate
  • Other:

Version Number of Plugin: 3.0.4
Device Tested On: Wiko kite (API 19)
Simulator Tested On:

Expected Behavior

It is supposed to return the heading value where the device heads at compared to the north

Actual Behavior

It returns 0

Steps to reproduce the Behavior

I'm calling the method like so :

var position = await CrossGeolocator.Current.GetPositionAsync(10000,null,true);
Latitude = position.Latitude.ToString();
Longitude = position.Longitude.ToString();
Heading = position.Heading;

        System.Diagnostics.Debug.WriteLine("Position Status: " + position.Timestamp);
        System.Diagnostics.Debug.WriteLine("Position Latitude: " + position.Latitude);
        System.Diagnostics.Debug.WriteLine("Position Longitude: " + position.Longitude);
        System.Diagnostics.Debug.WriteLine("Position Heading: " + position.Heading);

Copied from original issue: jamesmontemagno/Xamarin.Plugins#307

[Android] Problem with Background Location Refresh

Version Number of Plugin:
-3.0.4
Device Tested On:
-Samsung Galaxy Grand 2 (Android 4.4)
-LG Nexus 4 (Android 5)
-Alcatel Touch Idol (Android 4.1)
Simulator Tested On:
-None

Bug

I am running the following code inside the main thread of the application (inside the PLC) having no issues with iOS as the app continues listening to location updates even when the app is in background or the device is locked. But the position doesn't update on Android once I put it on background. Am I doing something wrong?, should I change the code to run on a new task on Android?. That might be the problem, but it's strange that the code works flawlessly on iOS but just doesn't seem to work on Android.

Code (The relevant parts)

Locator = CrossGeolocator.Current;
Locator.AllowsBackgroundUpdates = true;
Locator.DesiredAccuracy = DESIRED_ACCURACY;
await Locator.StartListeningAsync(MINIMUM_TIME, MINIMUM_DISTANCE, false);
Locator.PositionChanged += OnPositionChangedHandler;

Indicate units required in function summarys

Feature Request:

Can you change the summary comments on the functions to indicate what units are required for the parameters?
for example
locator.StartListeningAsync(minTime, minDistance);

I can tell minTime is milliseconds from your code (at least for Android), having it in the comments would of saved me confirming :-)

Add the heading of the raw GPS locations on iOS to the default position instead of relying purely on the compass for the heading

From @zezioen on February 12, 2016 10:2

When the UpdatePosition method is called it creates a new Location object and supplies it with the Latitude, Longitude, Accuracy, Altitude & Altitude Accuracy if available, Timestamp and Speed. It does not add the Heading supplied by the CLLocation by default.

The only way to get an 'heading' is by setting the 'includeHeading' in the StartListeningAsync to true but this does not report the heading of the GPS but where the user is pointing their device since it returns the compass heading.

The change I would like to see is to have the Compass heading be separate of the GPS heading and that the GeoLocator plugin reports the GPS heading on iOS instead of the Compass heading.

This issue doesn't seem to be an issue on Android as there the includeHeading doesn't trigger a compass heading but uses the real GPS Heading.

Copied from original issue: jamesmontemagno/Xamarin.Plugins#219

CrossGeolocator does not prompt for Location permission

From @pauldiston on June 7, 2016 12:31

Please take a moment to fill out the following (change to preview to check or place x in []) and remove all unused areas

This is a

  • Bug

Which plugin does this impact:

  • Geolocator

Bug

Version Number of Plugin: 3.0.4
Device Tested On: LG K8 (K350)
Simulator Tested On: N/A

Expected Behavior

Location permission should be prompted for

Actual Behavior

Location permission is not prompted for

Steps to reproduce the Behavior

Create instance of GeoLocator and call StartListeningAsync

Copied from original issue: jamesmontemagno/Xamarin.Plugins#325

Network provider on Android 5.0 doesn' retrieve geolocation on Background mode

Bug

Version Number of Plugin: 3.0.4
Device Tested On:
Samsung s3 mini, Android 4: ok
Huawei P8 Lite, Android 5: issue
Alcatel Pixi 4, Android 6: ok
Simulator Tested On: none

Expected Behavior

As a user I woud like to retrieve geolocation every specified interval, when the phone is locked on background mode.

Actual Behavior

Geolocations are not beeing retrieved when the device is locked within network provider. This happens just on Huaweii P8 Lite.

Steps to reproduce the Behavior

1/ Run this code
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 100;
locator.AllowsBackgroundUpdates = true;
await locator.StartListeningAsync(1000 * 60 * 5, 0, false);
2/ Stay in the building or somewhere where the network provider is in use.

Is it expected behaviour or a bug? Does it mean that network provider sensor is not charged on Huaweii P8 lite and this is the reason why it doesn't retirieve any geolocation? In that case could be there some detection, that this sensor doesn't work on background?

System.ArgumentNullException: Value cannot be null. Parameter name: cancel

Please fill out either the bug or feature request section and remove whatever section you are not using.

Bug

got an error
System.ArgumentNullException: Value cannot be null.

Parameter name: cancel

Version Number of Plugin: 3.0.4

Simulator Tested On

Steps to reproduce the Behavior

installed the nuget to both the plc and in the native application Android .

in my constructor i coded

try
{
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 50;

            var position = await locator.GetPositionAsync(timeoutMilliseconds: 10000);

            dynamic p1 = position.Timestamp;
            p1 = position.Latitude;
            p1 = position.Longitude;
        }
        catch (Exception ex)
        {
            DisplayAlert("", ex.Message, "");
        }

i got an exception as mentions.

the stack trace is like :

{System.Threading.Tasks.TaskCanceledException: A task was canceled.\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0002d] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:179 \n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 \n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 \n at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 \n at Plugin.Geolocator.GeolocatorImplementation+<GetPositionAsync>d__27.MoveNext () [0x00597] in C:\projects\xamarin-plugins\Geolocator\Geolocator\Geolocator.Plugin.Android\GeolocatorImplementation.cs:175 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 \n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00027] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:176 \n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 \n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 \n at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357 \n at TicTacToe.Views.GeolocatorPage+d__0.MoveNext () [0x00075] in c:\Users\sivaprasad.sr\Documents\Visual Studio 2013\Projects\TicTacToe\TicTacToe\TicTacToe\Views\GeolocatorPage.xaml.cs:28 }

Unable to check for or request permissions

I'm using the Mac version of Xamarin Studio and am trying the demo in this project on Android, and it basically does not work. The chief problem seems to be that it is unable to check for permissions because the method is not found.

System.MissingMethodException: Method 'ContextCompat.CheckSelfPermission' not found. at Plugin.Geolocator.GeolocatorImplementation+<GetPositionAsync>d__27.MoveNext () [0x00041] in C:\projects\xamarin-plugins\Geolocator\Geolocator\Geolocator.Plugin.Android\GeolocatorImplementation.cs:96 at --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
at GeolocatorSample.App+c__AnonStorey1+c__async0.MoveNext () [0x000b0] in /Users/foo/Projects/GeolocatorPlugin/samples/GeolocatorSample/GeolocatorSample/App.cs:28
at --- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__0 (System.Object state) [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018
at Android.App.SyncContext+c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:18
at Java.Lang.Thread+RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
at Java.Lang.IRunnableInvoker.n_Run (IntPtr jnienv, IntPtr native__this) [0x00009] in /Users/builder/data/lanes/3540/1cf254db/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Java.Lang.IRunnable.cs:81
at at (wrapper dynamic-method) System.Object:3cd1cf1f-37ea-43e5-bd59-06d3372c9505 (intptr,intptr)
`

PositionChanged giving new GPS position when device is in static position

Please fill out either the bug or feature request section and remove whatever section you are not using.

Bug (or may not be)

Hi James, i'm new to xamarin and also new to implementing Geo services solution.

The issue I'm facing currently is that if I put the phone on a static location (e.g on the table) without moving it, but then I noticed the PositionChanged event will keep firing periodically and give a new GPS location, isn't the GPS location of the phone should be always the same if it is in static position without moving around?

Is there anything that I have missed out? Please kindly advise.
Much Appreciated and Thanks.

Version Number of Plugin: 1.0.3
Device Tested On: 31 October 2016
Simulator Tested On: Nil

Expected Behavior

PositionChanged to retain the same GPS position when device is in static position

Actual Behavior

PositionChanged giving new GPS position when device is in static position

Steps to reproduce the Behavior

Below is partial of my code implementation.

var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 50;
locator.PositionChanged += (s, e) =>
{

             try
             {
                 var newPosition = e.Position;
                 Position newLogPosition = new Position(newPosition.Latitude, newPosition.Longitude);    
                 labelNewGPS.Text = "New GPS Location : Latitude :" + newLogPosition.Latitude + ", Longitude: " + newLogPosition.Longitude; ;
             }
                 catch (Exception ex)
             {
                 labelErrorMessage.Text = "Trip Log encountered error - " + ex.Message.ToString();
             }
    };
    locator.PositionError += (s, e) =>
    {
          labelErrorMessage.Text = "Trip Log encountered error - " + e.Error.ToString();
    };

    ......
    ......

   if (!locator.IsListening)
   {
          await locator.StartListeningAsync(1000, 0);
   }

Feature Request:

Please fill in what you would like

DesiredAccuracy not applied to the CLLocationManager in iOS

Bug

The property DesiredAccuracy is not applied to the CLLocationManager in GetPositionAsync method, and this causes the devices to try to get the best accuracy even if it's not needed.

I saw that the verification of the accuracy is done manually in the GeolocationSingleUpdateDelegate.

Using the xCode instuments, the log of Location Energy Impact outputs this:

Time CLLocationManager Event Thread
00:35.575.500 0x1041f18d0 Created <0xaa0a8>
00:35.575.543 0x1041f18d0 Changing accuracy to kCLLocationAccuracyBest <0xaa0a8>
00:55.607.086 0x1041f18d0 Released worker_thread 0xaa180

Version Number of Plugin: 4.0.0-beta12
Device Tested On: iPhone 5s, iOS10.1
Simulator Tested On: iPhone simulator, iOS 10.1

Expected Behavior

is to apply the DesiredAccuracy to the manager to save battery power, and get faster locks.

Actual Behavior

the manager uses kCLLocationAccuracyBest by default, and ignores the DesiredAccuracy parameter.

Steps to reproduce the Behavior

		var locator = CrossGeolocator.Current;
		locator.DesiredAccuracy = 3000;
		Position position = await locator.GetPositionAsync(timeoutMilliseconds: 20000);

TaskCanceledException when running GeolocatorSample on subsequent runs

Bug

Version Number of Plugin: 3.0.4.0
Simulator Tested On: Android Emulator via Visual studio
image

Expected Behavior

Get geolocation position

Actual Behavior

First run was successful
subsequent runs all resulted in the following
image

Steps to reproduce the Behavior

  1. Open the vanilla GeolocatorSample solution (I downloaded the sample solution a hour prior to this post from here)
  2. Select the Android project as startup
  3. Run with emulation settings from above image.
  4. Press GETGPS
  5. Repeat 1-4 once

Creating IGeolocator object in App.cs on Android with Xamarin 4.2.1.73 crashes app with System.NullReferenceException..

Please fill out either the bug or feature request section and remove whatever section you are not using.

Bug

Creating IGeolocator object in App.cs on Android with Xamarin 4.2.1.73 crashes app with System.NullReferenceException
DebugOutputWindow.txt
screen1
screen2

Version Number of Plugin: 3.0.4
Device Tested On:
Simulator Tested On: VS Emulator 5.1" Marshmallow (6.0.0) Android 6.0 API 23

Expected Behavior

After creating the location object, the app code should continue to execute. Sample creation of object below:
public static IGeolocator loc = CrossGeolocator.Current;

Actual Behavior

crashes app with System.NullReferenceException

Steps to reproduce the Behavior

Feature Request:

Please fill in what you would like

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.