Solved

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

Posted on 2014-10-15
5
822 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 77

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ifconfig 4 69
open source backup solution 1 36
awk sed 8 63
awk file 6 77
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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.

790 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