Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How to Get Current Location Instantly?

$
0
0

Hi all,

I am using the following code to request current location:

private void RequestCurrentLocation()
{
    Criteria locationCriteria = new Criteria () { Accuracy = Accuracy.NoRequirement, PowerRequirement = Power.NoRequirement };

    this.mgr = GetSystemService (Context.LocationService) as LocationManager;
    String locationProvider = this.mgr.GetBestProvider (locationCriteria, true);
    this.mgr.RequestLocationUpdates (locationProvider, 0, 0, this);
}

As I need location only once, so I call RemoveUpdates() as soon as OnLocationChanged is raised and then carry on with rest of the working:

public void OnLocationChanged (Location location)
{
    this.mgr.RemoveUpdates (this);

    //Rest of the method
}

I face two issues:

1) Although I have provided zero in the distance and time parameters of RequestLocationUpdates but it still needs at least 2-3 seconds before the OnLocationChanged is triggered. How can I make it instantaneous?

2) I intermittently face the issue that the OnLocationChanged event does not fire at all. Yesterday I spent the whole day to get my code working which was flawlessly working a day earlier. It's really strange that something works properly one day and the next day it simply stops even with the very same source code! Can somebody give me an idea?

Thanks.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>