Get custom latitude and longitude in Java

I see that this question is asked a lot here for Java, but every one that I see seems to be Android-oriented: I need a way to get the current latitude and longitude of the user when they call, it comes from a computer, not a mobile device. I know this is possible in C #, but I'm not sure exactly how to do this in Java. I used to use the Google Maps leftover API: however, it wants to get the address as input, and I just want to get a custom lat / lon, which, in my opinion, is easier than calling Google. Any help would be greatly appreciated.

+4
source share
2 answers

Currently, Java does not provide a general platform-independent API for obtaining location. However, there may be platform specific methods.

Most desktop implementations will be bound by IP address; you can use these services with Java (The best way to get geolocation in Java ). However, if operating systems provide a more general API, they can use any GPS equipment.

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

It details the Gnome-provided library , as well as recording support plans in KDE .

+4
source

The reasons you cannot do this for computers in general is that computers in general are pretty obvious when you think about it:

  • Computers generally do not have built-in GPS devices. Therefore, the computer cannot tell you on what basis.

  • Another approach is to try to map the IP address to the physical location. This is unreliable because IP addresses are not primarily associated with physical locations. Geolocation by IP address will only work on the fact that the network service provider of the user can (and wants to) provide location information to third parties. In practice, this information is very "heterogeneous." Another problem is that you need to rely on an external "geolocation service" to get information. It is not part of the standard Java platform.

  • There is another approach based on the geolocation of Wi-Fi access points 1 . This link is in more detail: http://gps.about.com/od/glossary/g/wifi_position.htm . However, this depends on which user of the WiFi provider registered their lat / long, and the user turned on WiFi.


1 - I remember how a colleague was developing the iPhone, noting that he got more accurate geolocation on the iPhone (with GPS) when WiFi was turned on.

+4
source

All Articles