Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Determine a user geolocation of a c# app
Posted
Comments
Ahmed Bensaid 8-Mar-14 14:26pm    
http://blog.psychocoder.net/2012/08/26/c-meet-geolocation-geolocation-meet-c/
BillWoodruff 8-Mar-14 21:53pm    
What type of GPS sensing hardware does your computer have ? If your computer has no GPS hardware, then all you can do is try and get the IP address of the current Internet connection, and then get location from that: that's possibly very inaccurate; the server handling the IP address may be a great distance from the user with that IP address.

1 solution

Hello,

There is an assembly in .net that wraps all that! it is part of .net 4 and 4.5 see here:

http://msdn.microsoft.com/en-us/library/system.device.location(v=vs.100).aspx[^]

Here is a good sample:

http://code.msdn.microsoft.com/windowsdesktop/Windows-7-Geolocation-API-25585fac[^]


It's just a few lines of code:

C#
var watcher = new GeoCoordinateWatcher(); 
watcher.TryStart(false,TimeSpan.FromMilliseconds(5000)); 
var coord = watcher.Position.Location; 


You just need to make sure your computer sensors are enabled.

Valery.
 
Share this answer
 
v2
Comments
BillWoodruff 8-Mar-14 21:53pm    
Without GPS hardware in the computer you cannot use this technique.

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