If the watcher did find the computer’s location, the code uses the watcher’s Position.Location property to display the computer’s latitude and longitude. If it did not find the computer’s location, the code displays a message in the latitude TextBox. If the watcher’s status has changed to Ready, the program checks to see if the watcher found the computer’s location. TxtLat.Text = "Cannot find location data" Private void Watcher_StatusChanged(object sender, As I mentioned in the caveats, this event isn’t raised if the application doesn’t have permission to access the computer’s location. The following event handler catches that event. The watcher starts and raises its StatusChanged event to tell the program about its progress.
Post a comment if you figure out how to make TryStart work.
The TryStart method is supposed to make the object start and block until it is ready for business so the program could avoid using an event handler, but I couldn’t get it to work on my system. It then calls the watcher’s Start method to make start it asynchronously. The Form’s Load event handler creates the watcher and adds an event handler to its StatusChanged event. The code declares a GeoCoordinateWatcher. Watcher.StatusChanged += Watcher_StatusChanged Private void Form1_Load(object sender, EventArgs e) Private GeoCoordinateWatcher Watcher = null When the program starts, it executes the following code. The code includes the following using directive to make using the Location API easier. The Location API is defined in the System.Device DLL so add a reference to that library. If you haven’t given up yet and warped to another web page, here’s how the program works.