Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
1.44/5 (3 votes)
See more:
Hello,

Can we get our client location (latitude,longitude) using a win-form application ?

Thanks in advance.
Posted
Comments
[no name] 30-Jul-13 10:17am    
I suppose that would depend on how you are getting the location. Are you going to use some sort of GPS or address or what?
[no name] 30-Jul-13 10:30am    
I have to retrieve my current location using my laptop so no GPS i have search for many address but they don't return my location.
Sergey Alexandrovich Kryukov 30-Jul-13 10:54am    
Isn't 'l' in your user name a typo? :-)
—SA

1 solution

I have never used this but this looks like what you need. The documentation says if no GPS is available it will use Wi-Fi triangulation. I don't know if it would do the same for a wired connection. Without a GPS, it will not be as accurate as a GPS. Without a GPS, it is probably using the location of your ISP. Try it and let us know how it works.

See System.Device.Location Namespace[^] and GeoCoordinateWatcher Class[^].


I got this to work on Windows 8 Wi-Fi and wired connection. It is possible that the wired connection test used remembered coordinates from the Wi-Fi test.

Add a Reference to: System.Device

VB
Imports System.Device.Location

VB
Private WithEvents watcher As GeoCoordinateWatcher
Public Sub GetLocationDataEvent()
    watcher = New System.Device.Location.GeoCoordinateWatcher()
    AddHandler watcher.PositionChanged, AddressOf watcher_PositionChanged
    watcher.Start()
End Sub

Private Sub watcher_PositionChanged(ByVal sender As Object, ByVal e As GeoPositionChangedEventArgs(Of GeoCoordinate))
    MsgBox(e.Position.Location.Latitude.ToString & ", " & _
           e.Position.Location.Longitude.ToString)
    ' Stop receiving updates after the first one.
    watcher.Stop()
End Sub
 
Share this answer
 
v7
Comments
Thomas Daniels 30-Jul-13 11:27am    
Good answer, my 5!
Dave Kreskowiak 30-Jul-13 12:03pm    
Even this is a "rough guess". Right now, without access to GPS, my laptop thinks it's 21 miles from where it actually is!
Mike Meinz 30-Jul-13 12:10pm    
Yes, without a GPS it is not as accurate as a GPS. Without a GPS, it is probably using the location of your ISP. See .NET Location API.
Dave Kreskowiak 30-Jul-13 12:34pm    
Oh, I know that. I'm not sure the OP would...
Thanks7872 30-Jul-13 13:28pm    
Really good one. Upvoted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900