How to fetch current location of device when App is launched first time in windows 8.1 using c#? -


i want fetch current location when app launched first time. added following code in app.xaml.cs file problem facing taking lot of time fetch location. think happens because didn't got dialog allow or block location tracking.

var location=new windows.devices.geolocation.geolocator(); geoposition pos=await location.getgeopositionasync(); getlocation.lat = pos.coordinate.point.position.latitude.tostring();  getlocation.long = pos.coordinate.point.position.longitude.tostring(); 

the above code have added in onlaunched event in app.xaml.cs page , getlocation class storing current location.

can suggest might issue ?

if first time mean each time application opened (for single position session), tried solution , worked me.using windows.devices.geolocation, code follows:

public async void mylocationfinder()     {         geolocator mygeolocator = new geolocator();         mygeolocator.desiredaccuracyinmeters = 50;         try         {             geoposition mygeoposition = await mygeolocator.getgeopositionasync(                maximumage: timespan.fromminutes(5),                timeout: timespan.fromseconds(10) );             latitudetextblock.text = mygeoposition.coordinate.latitude.tostring("0.00");             longitudetextblock.text = mygeoposition.coordinate.longitude.tostring("0.00");         }         catch (unauthorizedaccessexception)         {             //the app doesn't has right capability or location master switch off             statustextblock.text = "location disabled in phone storage.";         }     } 

you can call mylocationfinder() method in onlaunched function of app.xaml.cs if you'll have remove textblock part code , can replace any variable declared globally store class in method.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -