1

I'm trying to obtain latitude and longitude using freegeoip from shell. When I try the following commands:

$ curl -s --get http://freegeoip.net/json/74.201.113.118 | grep -Po '(?<="latitude":)[^,}]*'

$ curl -s --get http://freegeoip.net/json/74.201.113.118 | grep -Po '(?<="longitude":)[^,}]*'

I'm able to obtain some values, but whenever I replace the ip adress with my own, the command just outputs 0. Any idea why?

iamdeit
  • 5,485
  • 4
  • 26
  • 40
Tuco
  • 902
  • 3
  • 18
  • 33
  • 1
    May be, your location is not in their database? Where is the location? For Germany it works fine. – Ali Ismayilov Sep 30 '16 at 19:55
  • Costa Rica, I'm guessing that it isn't in their database. :/ – Tuco Sep 30 '16 at 19:56
  • 2
    Do you use public ip or private ip? I tried one Costa Rica ip and there is data. http://freegeoip.net/json/201.199.180.130 – Ali Ismayilov Sep 30 '16 at 20:00
  • 1
    I was using private ip, just tried with public and it works, thanks for everyone's help! :) – Tuco Sep 30 '16 at 20:08
  • 1
    If you are doing it a lot, you might save the result of the `curl` in a variable and parse that rather than incurring network latency twice, by the way. – Mark Setchell Oct 01 '16 at 12:32

1 Answers1

1

The problem was using private ip. Since private ip is location independent, freegeoip.net retrieves nothing. Using public ip instead of private ip solves the problem.

Ali Ismayilov
  • 1,707
  • 3
  • 22
  • 37