Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get user's current latitude and longitude in Java

I see this question asked a lot here for Java, but every single one I see seems to be Android-centered: I need a way of getting the user's current latitude and longitude when they call is coming from a computer, not a mobile device. I know that this is doable in C#, but I'm not sure how exactly to do it in Java. I've used Google Maps' restful API before: however, it wants an address as input, and I just want to get the user's current lat/lon, which I feel is simpler than making a call to Google. Any help would be greatly appreciated.

like image 435
Graham Carling Avatar asked Feb 17 '23 21:02

Graham Carling


1 Answers

Java doesn't currently provide a general platform-independent API to get location. However, there may be platform-specific ways.

Most implementations on a desktop machine will geolocate via IP address; you can use these services from Java (Best way to get geo-location in Java). However, if operating systems provide a more general API, it can take advantage of any GPS hardware.

For Mac OS, https://superuser.com/questions/346302/is-there-a-way-to-access-os-x-location-services-from-the-command-line

There's detail here of a Gnome-provided library, and also a write-up of plans for support in KDE.

like image 94
Joe Avatar answered Feb 27 '23 21:02

Joe