 Okay, this is the first in a series on maps and locations. We're going to be looking at getting addresses from GPS locations, getting coordinates from addresses, getting street views, getting map views, putting markers on maps. And we're going to first be looking at a lot of shell and bash scripts to do this. And then we'll move on to JavaScript and future tutorials for interactive maps. And today we're going to do something very basic. We're going to get an address from GPS coordinates. Now in these tutorials I'm going to mostly be using Google Maps and their APIs. So the scripts I write will be under an open source GPL license but it's going to be utilizing a service online. In some cases it will be just utilizing a service that you can get information from and other ones we might actually be using some a little bit of scripts from Google which may not be fully open. But I find right now this is in my opinion from what I've experienced in mappings and locations, Google does the best job so that's what I use for this sort of stuff. And in certain cases such as this where we're grabbing information I see it as a service not software although in again future tutorials we're going to get into utilizing some of their JavaScript APIs in which case we actually will be using some of their codes. So up to you and your ethical, moral and technical decisions. So I just wanted to clarify that in this first tutorial here. So here we're going to be using Google's API to get information on a GPS location. So some of Google has a few different versions of their API and some of them are very very simple to use and we're going to be using them here with a script and we're going to be using, I'm going to be using WGet but you can use Curl if you'd like. They usually default to WGet because it's on pretty much all Linux systems that's built into busybox where Curl is might be a little more of advanced program but isn't as commonly installed by default although pretty much always available. So their API to get information on some on a location is very simple. You can ask for JSON format or XML format and most time I prefer JSON but actually my script today I'm going to use some XML just to mix things up but I'm going to show you both examples. So I'm going to say WGet, I'm going to say dash O dash that's an O not a zero it's for output that the dash means standard output which means it's going to display the content of a page to the shell rather than save it to a file. I'm going to do dash Q to say quiet so don't show me the process because it should be rather quick and then in quotations I'm going to paste a link here, boom. So we got HTTP maps excuse me Google dot com maps API Geo code and then here is where we specify whether we want XML or JSON. So first we're going to look at the JSON and then we can give it a latitude and I put in one just a random one from here in town and the longitude and then sensor false meaning we're not using a sensor so in fact I don't know what the fault probably could get rid of that last whole part that's just what I have my notes from a couple years ago a lot of these earlier scripts here that we're going to be going over stuff that I have notes on that I did years ago and actually haven't played with too much since then let's go ahead and enter and we should get some JSON output with a bunch of information on those GPS coordinates. Now there'll be stuff in here the you can get the you know the address you can get just the number you can get the name you can get the the county you can get the city the state and if it's a business I think the business will show up in there. What we're going to look for today is just the full address like so. So that's the JSON output again if I clear the screen and run the same command I hit up out to bring up the last command and just say change this to JSON I can change this to XML and I can go ahead and hit enter and there we go we get all the same information but in XML format again I personally prefer JSON I think it's a little bit cleaner and easier to read in a lot of cases and easier to pull stuff out of but just for fun today we're going to write a code using the XML and again we're going to be looking for the full address something like that the formatted address now if you run that same command you can see that the tag for that is called formatted address and I can say grep and I can paste in formatted address so we pipe that output into formatted address and we should get lines that only have formatted address on them and as you can see there's a few of them but the first one's going to be the one we want so what I can do here is I can just say head dash and one and that will give me just the first line that comes up with formatted address now we can move the tags there's different ways to do this regular expressions programs probably do it I could probably do HTML to text I'm just going to use cut just because I know it's a command that will be installed on your system by default so I'm going to run it through two cut commands I can say cut dash the limiter of D and I'm sorry the limiter of the greater than symbol and I can say field two and then I can say cut dash D less than symbol field one and there we go we get an output of just the address the full address the mailing address there so what we're going to do here is again we've gave it GPS coordinates the latitude and longitude here we asked for XML output and then we took that output and we said grep meaning look for and we look for this tag we're say okay head start at the top and dash and the number of lines just one finding the first response we get and then we're going to say okay we're going to cut this we're going to cut this line into columns well what do we want to divide it up by well first time we're divided up by these greater than symbols and we're going to say field two so if this is our first delimiter our first divider here we're going to say okay field two this will be field one over here everything before that this will be field two over here okay so well actually this should be field two over here up to the next greater than symbol so we have all that but we still have the next portion of this little tag here so that's what the second come cut command does it says cut with a delimiter of the less than symbol here and we're going to say field one so everything before that because you remember well let me show you here let me clear the screen run that command again without the second cut just to clarify and you can see you get the output here and it still has this here so we want to get rid of that and that's what the second cut command does it says look at the less than symbol right here and only look at stuff before that which would give us this our address let's go ahead and put that into a script I'm gonna use vim as my text editor you can use whatever text editor you would like so let me go ahead and highlight this and I've mentioned this before a lot of you already know this in a Linux and I think most Unix and Unix based environments once you highlight something it's copied to your clipboard and you can use center click to paste which will probably be if you're using a regular mouse your scroll button if you just click it down you can paste so I very highlighted it so now I can paste it I can say vim and I'll call my text address.sh now I want this to be a bash script so I'll give it the shebang line if bash really this isn't I think we're doing anything here that's bash that it's you have to have bash for specific there we go this is all tools pretty much all external tools so this should work with any script in language I'm gonna use bash just because it's default on most systems but it might be better actually to do sh because most systems sh will default to bash or whatever your default shell is so what I'm gonna do here now is I'm going to paste in my command let's clean it up a little bit first off let's go ahead and let's create some variables and I'm gonna create a latitude and a longitude variable called them Latin long but we'll just create variables we want the user to be able to give us the latitude and longitude so if we're using arguments in bash in a shell script dollar sign one will be the first argument dollar sign two would be the second argument so our user will have to give us the coordinates in that order and that will be allow us to shorten this up a little bit as well so we can say dollar sign lat really we could directly go dollar sign one dollar sign two here but just in case you're gonna use those you're gonna make the script longer it's better to take the arguments and put them into usable variables like so okay so this line is kind of wrapping around so we're gonna do is here's gonna say backslash and without any space we're gonna hit enter and then here I'll hit tab and we'll do that after each each pipe just to clean things up a little bit so it's still all one command we're just breaking it down to different lines to make it easier to read is what we're doing there so then up here so our script's pretty much done but we'll want to check for some stuff okay so right now let's go ahead save that change mod plus x to make it xql it's giving it permission to run now if I just run it without giving any arguments nothing no there's no output because we didn't give it any coordinates let me go ahead and give it the same coordinates we gave it before I'll go ahead and paste in the coordinates I got them in my notes here and now we do that and we get the address output and again we could change one of these numbers and as long as it's natural location there we go we got another address here so whatever coordinates you put in here I'll try putting something if this ends up in the ocean that's Cuba okay so we'll go back to this one here and clear the screen so it works but if we don't give it any output or let's see what happens if we give it one coordinate nothing happens because we're not giving it enough information so let's go ahead and give our user a little bit of help here and what we're gonna do is we're gonna add an if then statement we'll say if and we're gonna say pound I'll say in quotations pound dollar sign pound what's that saying okay the dollar sign one says first argument dollar sign two means second argument well dollar sign pound means the number of arguments I've gone over this a long time ago in an earlier tutorial but that's what it means the number of arguments we're gonna say two dash LT means less than so we're gonna say if the user doesn't give it least two arguments that's what we're saying here if the art the user doesn't give it least two arguments what are we gonna do well then we're gonna give them some sort of output so what we're gonna say is we're gonna say echo and we'll just say we'll give it some sort of message like input error and I'll say echo and we'll give them an example we'll say example usage and we'll say dollar sign zero now dollar sign zero one is your first argument dollar sign zero is actually the name of your command so they can rename this script whatever they want and it will still display because if I was to say oh you know do addresses like this that s8 address that sh well the script might be renamed something else and do we want to put the dot slash if it's installed to their system rather than just running it out of the script it wouldn't have that dot slash but if we do dollar sign zero it will show whatever the actual command they entered is as far as the name of the program and we'll get again give it some example coordinates here that I know will show an address and then we'll say exit one so end the script there so we don't need to make it re executable because it's still executable because it's still on our system but if I run it without coordinates it's gonna give us our input error message and it's gonna say example usage and it will give us the command that we put in and so they could just go oh let me try this out I'm just put that in all that works and if we do the same thing but we only put one variable we're still gonna get that error because we said check to see if they gave two arguments and they're only giving one so there that's how it works and actually usually when I do this I usually also put in this I usually say say for example usage I'll say usage and I'll say something like latitude and longitude how do you spell longitude longitude I think that's right close enough for right now so so they might see without this look oh example usage what are these numbers they may not know what this program does and I haven't made a man file for it or have any other comments in this script at all so that's a good thing to have too so now if they type it wrong it will not only show them an example but it will tell them what the usage actually is and just to show you see how this says dot slash address SH so if I was to rename my address script to Bob dot SH if I run it again with Bob dot SH you can see that using that dollar sign zero changes that message that's why we use dollar sign zero rather than putting the name of the program in there and that is it for this tutorial I want to point out a few things one all this all the codes in the series is gonna be on a github repository I created if you go to github.com forward slash metal x1000 that's my username click on repositories and then search for maps and locations right now it's the topic may or may not be you can come up here and just type in map and it will narrow it down and click in here and all the scripts from this series will be in here the bash ones will all be here there's the address script right there it's already there I set this all up for you so you can just grab the code from there if you want and then just have a look at it to test it out if your code is not working you can see if mine does so I hope you found that useful again all the code will be up online I thank you for watching and I hope that you visit my website filmsbychrist.com that's Chris of the K there should be a link in description and as always I hope that you have a great day okay this is an introduction to filmsbychrist.com I'm Chris that's Chris the K that's me right there my daughter ember and my wife Jennifer we pretty much live in the swamps of Florida I'm a firefighter by day as well as by night we work long hours but that's not why you're here you're here about the videos I put up on YouTube these videos are mainly about computers and programming which means most my videos look something like this and if that's what you're interested in great if not that's all right I do videos on other topics too such as video editing special effects photo editing 3d design and music creation if you are one of my viewers and you enjoy my videos my patreon page is a place where you can go to help support my videos so I asked that you take the time to go to my patreon page and look at different levels of rewards you can receive for different levels of backing there should be a link in the description of this video if you were watching it on YouTube otherwise you can visit patreon.com forward slash metal x1000 and I thank you for your time and your support have a great day