#!/bin/bash #set -x . ~/.password read -p "What is the number of the store? " STORE read -p "What is the street and number? " TPH_STR read -p "What is the postal code? " TPH_PCS GOOGLE=`lynx -dump -accept_all_cookies \ "http://maps.google.com/maps/geo?q=${TPH_STR},${TPH_PCS}+Belgium&output=csv&key=${GOOGLE_API_KEY}" ` LON2=`echo $GOOGLE|awk -F, '{print $3}'` LAT2=`echo $GOOGLE|awk -F, '{print $4}'` #LON2=51.218118 #LAT2=4.414331 echo $LON2 echo $LAT2 if [ "$LAT2" = "0" ] then echo "Wrong adress!" exit fi RADIUS=6372795.477598 CONVERT=`echo "scale=6; 180/(4*a(1))" | bc -l` test -f DISTANCE.csv && rm DISTANCE.csv # postalcode parameters for PC_LOC in `cat POSTCODE_LAT_LON` do PC=`echo $PC_LOC|awk -F, '{print $1}'` LON1=`echo $PC_LOC|awk -F, '{print $2}'` LAT1=`echo $PC_LOC|awk -F, '{print $3}'` #Measure the distance X=$(echo "(s($LAT1/$CONVERT)*s($LAT2/$CONVERT))+(c($LAT1/$CONVERT)*c($LAT2/$CONVERT)*c($LON2/$CONVERT-$LON1/$CONVERT))"|bc -l) DIST=$(echo "$RADIUS * a(sqrt(1-$X^2)/$X)"|bc -l|awk -F\. '{print $1}') #Output the distance printf "$STORE;$PC;$DIST\n" >> DISTANCE.csv printf "$STORE $PC $DIST \r" done exit