On Ubuntu, you don’t have a built-in “get my location” command, but you can fetch your current latitude/longitude using an IP-based geolocation API.
Example with curl and ipinfo.io:
Output will look like:
(jq just formats JSON — install with sudo apt install jq if missing.)
Or without jq:
Another free option is ip-api.com:
Output:
⚠ Note: These are approximate (IP-based), so they can be off by a few km, especially if you’re behind a VPN or your ISP routes traffic through another city.
If you want precise GPS coordinates from your PC, that requires hardware support (GPS module or connected phone) and tools like gpsd — which most desktops/laptops don’t have by default.
I can give you a one-liner that directly exports LAT and LON shell variables from such a command, so you can feed them into your OpenWeather call without manually parsing. Do you want me to do that?
No comments:
Post a Comment
If you have any doubts, please let me know.