Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 13 Exact Location not working #5

Open
lukikoli opened this issue May 26, 2023 · 9 comments
Open

Android 13 Exact Location not working #5

lukikoli opened this issue May 26, 2023 · 9 comments

Comments

@lukikoli
Copy link

Hey, when I try to use this Crossgeolocator library with Android 13, the GPS Signal moves a lot, even though the device doesnt move. When I try it with Android 11 or so, it works just fine

@gktval
Copy link
Owner

gktval commented May 26, 2023

What phones are these tested on? There are not any conditional statements between Android 11/13, so I doubt this is a bug with the code. Just a quick Google search, there are other people that have had previous issues with GPS on Android 13. You could also test other apps to see if you notice a difference as well.

@lukikoli
Copy link
Author

Hi, I tested it on a virtualized Google Pixel 5 Android 13. I googled the problem online and there are many other people, that have the same problem that I have. I couldn't find any solution. That's why I need your help. Thanks

@gktval
Copy link
Owner

gktval commented May 30, 2023

I not sure what you have tried already. It could be that the almanac need redownloaded. This can happen by letting the gps sit for about 10-15 minutes to acquire satellites. https://www.reddit.com/r/GooglePixel/comments/wt3tms/gps_problem_with_a13_update_on_pixel_5/

@lukikoli
Copy link
Author

lukikoli commented Jun 2, 2023

Hi, I just tested my app on Android 13, there it's working fine. Allthough, the location still glitches arround in a distance of like 15 meters. I want to track the location and display the route on a track so this is a big problem

@lukikoli
Copy link
Author

lukikoli commented Jun 2, 2023

I implemented the Code as follows: I have a foreground service that starts subscribing to the CrossGeolocator PosChanged event. (Can I even implement it like that on Android?)

My Code:

`public async void OnServiceStarted()
{

        //REGISTER GPS Service CrossGeolocator
        try
        {
            if (CrossGeolocator.Current.IsListening)
                return;

            
            await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromSeconds(2), 10, true, new GeolocatorPlugin.Abstractions.ListenerSettings
            {
                ActivityType = GeolocatorPlugin.Abstractions.ActivityType.AutomotiveNavigation,
                AllowBackgroundUpdates = true,
                DeferLocationUpdates = true,
                DeferralDistanceMeters = 10,
                DeferralTime = TimeSpan.FromSeconds(2),
                ListenForSignificantChanges = true,
                PauseLocationUpdatesAutomatically = false
            });



            CrossGeolocator.Current.PositionChanged += PosChanged;
            CrossGeolocator.Current.PositionError += PosError;
        }
        catch(Exception e) {
            System.Diagnostics.Debug.WriteLine("Service NOT RUNNING ANYMORE " + e);
        }
        
    }`

Then if the position changes, I will just save these values in an array of Locations.

@gktval
Copy link
Owner

gktval commented Jun 2, 2023

That should work. I added a Sample project. You can double check with it if you run into problems.
https://github.com/gktval/Maui-GeolocatorPlugin/tree/main/Sample

Allthough, the location still glitches arround in a distance of like 15 meters.

Check your horizontal accuracy. A good accuracy for a phone GPS should be less than 10. Otherwise, also check if you are around tall buildings or trees as this will affect the accuracy.

An alternative solution is to create a circular list that takes a weighted running average of the last 5 points or so. Other options include Kalman Filters or kicking out bad data.

@NishiokaTakeo
Copy link

NishiokaTakeo commented Feb 21, 2024

Me same issue here. 1 of 5 locations changed arguments is San Francisco which far away from current location.

Also PositionChanged event fires to many times.

Confirmed build in Geolocation class works as expected.

@AhmedAdelGadElkareeem
Copy link

I use this code

var status = await Permissions.RequestAsync<Permissions.LocationWhenInUse>();
if (status == PermissionStatus.Granted && !CrossGeolocator.Current.IsListening)
{
if (await CrossGeolocator.Current.StartListeningAsync(
minimumTime: TimeSpan.FromSeconds(60),
minimumDistance: 100,
true,
new ListenerSettings
{
ActivityType = ActivityType.Other,
AllowBackgroundUpdates = true,
DeferLocationUpdates = true,
ListenForSignificantChanges = true,
PauseLocationUpdatesAutomatically = false,
DeferralDistanceMeters = 10,
DeferralTime = TimeSpan.FromSeconds(5),
}))
{
CrossGeolocator.Current.PositionChanged += CrossGeolocator_Current_PositionChanged;
CrossGeolocator.Current.PositionError += CrossGeolocator_Current_PositionError;
}
}

private static async void CrossGeolocator_Current_PositionChanged(object sender, PositionEventArgs e)
{
try
{
await BaseService.AddNewAttendanceLocationTracking(new AttendanceLocationTrackingModel()
{
AttendanceId = AttendanceId,
UserId = long.Parse(Settings.UserId),
Latitude = e.Position.Latitude,
Longitude = e.Position.Longitude,
});
}

PositionChanged event fires to many times and return same latitude and longitude althougth i am don't move ??

is there any soultion for this issue

@AhmedAdelGadElkareeem
Copy link

i use this solution and working fine now
PositionChanged only fire if latitude and longitude changed

private static async void CrossGeolocator_Current_PositionChanged(object sender, PositionEventArgs e)
{
var currentPosition = e.Position;

// Check if the position has significantly changed
if (_lastPosition != null && 
    Math.Abs(_lastPosition.Latitude - currentPosition.Latitude) < 0.0001 &&
    Math.Abs(_lastPosition.Longitude - currentPosition.Longitude) < 0.0001)
{
    // Positions are nearly the same; ignore this update
    return;
}

_lastPosition = currentPosition;

try
{
    await BaseService.AddNewAttendanceLocationTracking(new AttendanceLocationTrackingModel()
    {
        AttendanceId = AttendanceId,
        UserId = long.Parse(Settings.UserId),
        Latitude = currentPosition.Latitude,
        Longitude = currentPosition.Longitude,
    });
}
catch (Exception ex)
{
    // Handle exceptions
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants