I'm writing a windows 7 desktop C# app and I need to write code when there is a location sensor. I have this:
public string check(string stop)
{
GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();
watcher.Start();
watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
return null;
}
static void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
switch (e.Status)
{
case GeoPositionStatus.Initializing:
Console.WriteLine("Working on location fix");
break;
case GeoPositionStatus.Ready:
Console.WriteLine("Have location");
break;
case GeoPositionStatus.NoData:
Console.WriteLine("No data");
break;
case GeoPositionStatus.Disabled:
Console.WriteLine("Disabled");
break;
}
MessageBox.Show("GO");
}
This is really just to see if it grabs the latitude and longitude, but I don't have a sensor and I just want to know, will this work if a laptop does have a sensor? I can't afford to get a sensor yet so I would like to have the code and move on until I can aquire one. Also, I need to stop the geocoordinatewatcher when the user logs out, so since I cant stop this in a different function, if I start another and stop that one will that stop all?These functions are called from a webapge and there are no buttons on my form. The function called when a user logs out will be stop();. And just in case someone wanted to suggest it, I can't use GeoSense.
Old question but here goes anyway:
I think your answer is not a problem with the sensor but with the scope of the watcher variable. You start the watcher then register for the event and then your watcher losses scope.
GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();
public string check(string stop)
{
watcher.Start();...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.