Solved

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

Posted on 2014-10-15
5
777 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
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 76

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now