Solved

Bash script to get GEO location from http://freegeoip.net/

Posted on 2014-10-15
5
863 Views
Last Modified: 2014-10-19
Could someone share some Linux bash code which uses the http://freegeoip.net/ service to get lat/lon into two variables.

I basically just need to add this functionality to a bash script I have, picking up the lat/lon of the location I am running the script from.

As I understand it, http://freegeoip.net/ is 100% free to use regardless of use.
0
Comment
Question by:projects
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 40383345
LATLON=$(wget -o /dev/null -O - http://freegeoip.net/xml | awk -F'<|>' '/Latitude|Longitude/ {print $3}')

LAT=$(cut -f1 -d" " <<< $LATLON)
LON=$(cut -f2 -d" " <<< $LATLON)

echo "Latitude: " $LAT
echo "Longitude:" $LON
0
 

Author Comment

by:projects
ID: 40383482
Seems to work fine.

Any chance you could tell me what type of field and size I might use in MySQL to store these and other potential results?

Latitude:  xx.7685
Longitude: -xx2.8815

It sounds like using MySQL Spatial Extensions is the way to go but I've not found any examples of what to set the new fields to.

Currently, I have;

       geo_lat       decimal(10,8)       No       None       NULL       
      geo_lon       decimal(11,8)       No       None       NULL

And the data being stored looks like;

      34.76850000       -112.88150000
0
 
LVL 78

Expert Comment

by:arnold
ID: 40383673
What are you looking for? converting the data and rendering it as  34° 46' 6.6" N 112° 52' 53.4" W?

some avoid the float/decimal by multiplying the data by 10^8 and storing the data as int (10) when when needed, divide by 10^8
i.e your stored data will be 3476850000 -11288150000
Some only go to the six digit precision or fewer, depending on how "precise".
0
 

Expert Comment

by:erix molinie
ID: 40389740
Hi,
it's an interesting problem or case and the answers gave to you are good.
but, as it has been already asked you, what are you trying to do.
"freegeoip" is certainly a good website but it's not accurate and it relies on informations provided by Internet/Phone companies I suppose. For example, if I take my @IP, the localization is 100km far from where I am..
The country is good, the region is good but not the city/town/village.
Regards
Erix
0
 

Author Comment

by:projects
ID: 40390360
What I am trying to do is simply to get the lon/lat geo location of something using a script.
I need to use a 100% free GEO location service which doesn't impose limits in any manner including for commercial use.

I only need to use it once to set the device unless it's position changes which would be very rare. My usage would be very low.

I already awarded the solution because I was looking for a little code to do this.


Another that I really like is
http://www.datasciencetoolkit.org/developerdocs#ip2coordinates

I like this one because I already have the address information in the database and it looks like if I sent this one the IP and some of the address info, it would be more accurate?

I am going to post a new question. Thanks.
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question