geolocation - Send device's current location to Azure service in Windows 8.1 -
i developing location tracking windows mobile app , want send current location azure service background task. getting current location done. show current location in app tile. likewise showing location in tile want send location azure service. how can send current location azure service continuously rest of devices can see device's location.
so far code
public sealed class backgroundgeofencetask : ibackgroundtask { //azure service //private mobileservicecollection<location, location> items; //private imobileservicetable<location> locationtable = app.waytoschool5client.gettable<location>(); backgroundtaskdeferral _deferral = null; accelerometer _accelerometer = null; geolocator _locator = new geolocator(); public void run(ibackgroundtaskinstance taskinstance) { _deferral = taskinstance.getdeferral(); try { // force gps quality readings _locator.desiredaccuracy = positionaccuracy.high; taskinstance.canceled += taskinstance_canceled; _accelerometer = windows.devices.sensors.accelerometer.getdefault(); _accelerometer.reportinterval = _accelerometer.minimumreportinterval > 5000 ? _accelerometer.minimumreportinterval : 5000; _accelerometer.readingchanged += accelerometer_readingchanged; } catch (exception ex) { // add chosen analytics here system.diagnostics.debug.writeline(ex); } } void taskinstance_canceled(ibackgroundtaskinstance sender, backgroundtaskcancellationreason reason) { _deferral.complete(); } async void accelerometer_readingchanged(windows.devices.sensors.accelerometer sender, windows.devices.sensors.accelerometerreadingchangedeventargs args) { try { if (_locator.locationstatus != positionstatus.disabled) { try { geoposition pos = await _locator.getgeopositionasync(); xmldocument xml = tileupdatemanager.gettemplatecontent(tiletemplatetype.tilesquare150x150text03); var tileelements = xml.getelementsbytagname("text"); tileelements[0].appendchild(xml.createtextnode(pos.coordinate.point.position.latitude.tostring("f5"))); tileelements[1].appendchild(xml.createtextnode(pos.coordinate.point.position.longitude.tostring("f5"))); tileelements[2].appendchild(xml.createtextnode(pos.coordinate.point.position.altitude.tostring("f0"))); tilenotification tile = new tilenotification(xml); tileupdater updater = tileupdatemanager.createtileupdaterforapplication(); updater.update(tile); //send locationto azure //var db = new location { serviceid = "sid", currentlatitude = pos.coordinate.point.position.longitude.tostring(), currentlongitude = pos.coordinate.point.position.longitude.tostring() }; //await locationtable.insertasync(db); } catch (exception ex) { if (ex.hresult != unchecked((int)0x800705b4)) { system.diagnostics.debug.writeline(ex); } } } } catch (exception ex) { system.diagnostics.debug.writeline(ex); } } public void dispose() { if (_accelerometer != null) { _accelerometer.readingchanged -= accelerometer_readingchanged; _accelerometer.reportinterval = 0; } } }
location.cs
public class location { public string serviceid { get; set; } public string currentlatitude { get; set; } public string currentlongitude { get; set; } }
Comments
Post a Comment