Fast way to get User's Location (and city name)
Hello,
I'd like to know if there is a faster way to get users' location I'm using the code below, and I find it a little slow about 2-5 seconds to get a location
[CODE] public async Task<Geoposition> UserLocation()
{
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
try
{
Geoposition geoposition = await geolocator.GetGeopositionAsync(
maximumAge: TimeSpan.FromMinutes(5),
timeout: TimeSpan.FromSeconds(10)
);
return geoposition;
}
catch (Exception ex)
{
throw ex;
}
}[/CODE]
And also is there a way to get the location's city name in offline mode, ("[I]Microsoft.Phone.Maps.Services[/I]" needs internet connexion.)
Thank you,
Re: Fast way to get User's Location (and city name)
Hello,
The geolocator used cellular or GPS triangulation to get the location, the more accurate it is, the longer it will take to get a fix on the location, 2-5seconds are "acceptable" I think.
For the location city name , you can use the [URL="http://msdn.microsoft.com/en-US/library/windowsphone/develop/microsoft.phone.maps.services.reversegeocodequery(v=vs.105).aspx"]ReverseGeocodeQuery [/URL]class, this works offline.
Hope this helps,
Re: Fast way to get User's Location (and city name)
[QUOTE=WPMorocco;911974]Hello,
The geolocator used cellular or GPS triangulation to get the location, the more accurate it is, the longer it will take to get a fix on the location, 2-5seconds are "acceptable" I think.[/QUOTE]
So if I leave this parameter by default, geolocator.DesiredAccuracyInMeters = 50; It would go faster ?
(can I control which way to get Location (Gps/cellular/Wifi) ?)
[QUOTE=WPMorocco;911974]For the location city name , you can use the [URL="http://msdn.microsoft.com/en-US/library/windowsphone/develop/microsoft.phone.maps.services.reversegeocodequery(v=vs.105).aspx"]ReverseGeocodeQuery [/URL]class, this works offline.[/QUOTE]
Oh sweet, I thought it needed internet connexion like for downloading a set of POIs,
Thank you WPMorocco,
Edit : I had a little issue getting User's Location in Application launch (like on foursquare), so I put my method in the constructor of the first page, then in the "[I]OnNavigatedTo[/I]", but in both cases the method "[I]GetGeopositionAsync[/I]" just hanged there without retrieving the location (more than 20 sec).
Putting it in the page Loaded event solved the problem.
So the app needs to be loaded before trying to retrieve User's Location.