ipLocnTest
1.0.0
Get decently featured maps in .NET, without any actual mapping API involved in your end!
Imports System.Device.Location
Put following code inside main class
DIm n = 0
Private Sub Watcher_StatusChanged(ByVal sender As Object, ByVal e As GeoPositionStatusChangedEventArgs)
n += 1
If e.Status = GeoPositionStatus.Ready Then
If Watcher.Position.Location.IsUnknown Then
txtlat = "Cannot find location data"
Else
txtlat = Watcher.Position.Location.Latitude.ToString() '.Substring(0, 7)
txtlong = Watcher.Position.Location.Longitude.ToString() '.Substring(0, 7)
End If
End If
If n < 10 Then
If txtlat <> "Cannot find location data" And Math.Abs(Val(txtlat)) > 0.0000001 Then
Watcher.Stop()
'the value of txtlat and txtlong has now been set to your location
End If
Else
Watcher.Stop()
'give user some indication of error/ handle the error (thrown when cannot find location)
End If
End Sub
Private Sub LocateMe()
n = 0
Watcher = New GeoCoordinateWatcher()
AddHandler Watcher.StatusChanged, AddressOf Watcher_StatusChanged
Watcher.Start()
End Sub
Call the LocateMe() sub when you require the location. For first use, a messagebox will pop up asking for permission to access location.
The values of txtlat and txtlong will be set to the latitude and longitude.
Note that this is usually not instantaneous, and may fail on the first try