 Okay, this is the second video in the series on maps and locations. We're still working with shell scripts, bash scripts here. And if you haven't watched the last week's tutorial, I suggest doing that. Hopefully I put an annotation on the screen to the full playlist and you'll be able to watch these as they come out. There'll be some things I skim over because we went over them last week. But we're using Google APIs here to grab some information. And last week we used the XML format. This week we're going to be using a JSON format just to change things up. It doesn't make a big difference either way with what we're doing. It doesn't matter how you're going to pull apart that information. And last week we put in GPS coordinates and we got an address. This week we're going to put in an address and get GPS coordinates. So again, the GPS, the Google APIs can make things very, very simple. And all we have to use is a URL. So I'm going to use Wget, but you can use curl if you prefer in your scripts. Then what I'm going to see here is Wget. And then I'm going to say dash O, not 0, but O for output, and then a dash for standard output, dash Q for quiet so we don't see the process bar and everything for Wget. And here I'll paste in an address. Now URL. Now the URL isn't complete here, but you can see this is HTTP. You can also use HTTPS, but then you have to tell Wget to ignore certificates or just in this case I'm using HTTP. Unless you're really concerned about people seeing what addresses you're searching. Okay, so in which case you wouldn't be using Google. Anyway, maps, Google APIs dot com, maps, API, Geo code. And this time we're going to say JSON, but you can do XML there and get the XML output. And then the argument we're giving it, we're going to pass it the address. So I'm just going to say 123 Fifth Avenue South, Naples, Florida. I live in Naples, Florida, so go ahead and do that. And we get the JSON output for that address. We get the full address. So last week we were looking at the format address you can see here that gives the zip code and everything. So keep in mind that you could use this to get full addresses. So if you wanted to have addresses formatted exactly the same, but having users input the address, as you can see this is not the exact address, I mean this is the address, but it's not the format I put it in. I put av and I put s not s. I left out the commas, I didn't put in the zip code, I didn't put in USA. So if you're creating a database and you're having someone enter in addresses, or you want to have a program that autocompletes addresses, you could use this as well. Kind of a side note, not our project today. What we want is the GPS coordinates. And as you can see, there's a few here. So which ones do we want? Well, you realize that these ones say bounds and then they have a latitude and longitude and then a slightly different latitude and longitude. These are the coordinates you would use if you wanted to draw a square around this property. It's the northeast and southeast corners and you can use those coordinates to create the address. And then there's other ones down here. What we want is just the location. This should give us, I guess, like the center point of that location. So we want to grab this information here. Now, we can look for lat and long, but they're right next to each other. So what I'm going to do, and since there's more than one of those, I'm going to look for location in quotations like this. Chances are there's not going to be another line that has the word location followed by and proceeded with quotations. So let's clear the screen running the same command. I'm going to pipe that into grep. And from there, I'm going to grep again that line that says the location. So I'm going to do that. I'm going to use single quotes so I can put the double quotes inside or I could just use backslashes, whichever you prefer. But I'm going to say location. Remember, this is case sensitive and let's tell grep not to be. So I do that and you can see I get that line. You can see it's the only line, which is a good thing. If there's more than one, we need to double check our script here. So hopefully this is consistent. I don't think there will be any other lines and any other examples that will have that. And if so, there might be more, hopefully the first one will be what we want. But I think it will be the only one in pretty much all cases. So we have that, but we want the lines after that actually. So what we're going to add to our grep command here is dash A2. And what that says is get this line and two lines after what we find as well. So we'll hit enter there and you can see we get the line we searched for and the two lines after it, which is great. So now we want to remove this line. So let's grab the last two lines. We have three lines, let's say tail dash and two. So we'll hit that and you can see we get two lines of output. Now we want to divide that up. We want to get everything on the right side of the colons there. So we'll say cut with a delimiter of colon and we'll say field two. And we'll say enter there and you can see we got them. And we got them on two different lines and there is a comma there. So I would say depending on how you want it formatted, I would either remove the comma or put them on the same line divided by a comma. That's usually commonly how coordinates are written. So let's go ahead and use the tr command, which will replace any single character with another single character. I'm going to say backslash n. You're going to go, oh, that's two characters. Backslash n represents one character. It's a new line character. So I'm going to do that and then over here I'm going to put a space because I think with tr if you leave a blank it's going to give you an error. Yeah, it can't be empty. So we'll put a space there. And so we have a little bit of an extra space there. We could remove that, but I'm going to stop there. You also notice that since we removed the new line character, now I'm technically not using bash shell here. I use zshell as my default shell. If we were using bash, this would be up here. And as you can see, we have that percent symbol, which is what I have set as my shell prompt. So really we want to add a new line after that. So if we were writing this in a script, we'd write add an extra command of something like echo with nothing in it. And that will just create a new line character. That's how I do it. Might be better ways. But there we go. We get our coordinates there all on one line divided by a comma. Again, you can remove these extra spaces or one of them if you wanted. I'm not going to bother doing that. Let's put all this quickly into a script. I'll just call the script gps.sh. I'm going to label it with a shebang line of bash. Really you can use sh, I went over that in the last tutorial. And let's quickly save that. And instead of typing everything out again, let's go ahead and highlight that. And then come in here. Again, I'm using vim as my text editor. Use whatever text editor you prefer. I'm going to paste that line in there by center clicking. And here we go. I'm going to come down here. Well, first things first, let's create our address variable. Just like last time we created latitude, longitude variables. I'm going to say address equals dollar sign one. Our first argument will be our address. And then here, instead of having the address, I'm going to say dollar sign address. And then to move everything along, I'm going to say each of my pipes are going to say backslash enter tab, backslash enter tab, again, no space or anything after the backslash that will screw things up for you. Backslash enter tab. You can leave it all online. This just makes it easier to read in a script, and then we'll put our echo command there. We'll save that since we just created it, we have to make it executable. Let's go ahead and clear our screen here, gps.sh, if I hit enter now, nothing happens. I didn't give it an address. Let's go ahead and give it an address. I'm going to give it an address. Now, if I was to, for example, use 123 5th Avenue South Naples, Florida, this is going to cause problems because each space is going to be recognized as a new argument. Now we can go ahead and put a backslash before each space, but it's easier to put quotations either single or double, regardless of whether you're using variables in there or not. So single or double quotes around it that says, everything between this is a single argument. We'll hit enter, and there we go. We get our coordinates. Okay, so now that we did that, let's go back into our script, and again, if you don't put anything, you get no output. We want to have some sort of message there for our user, and I'm just going to save us some time. I went over this in detail on how to, what all this is in the last tutorial, but I'm just going to paste it instead of typing it, and I'm going, so here we're saying if, and then this is the number of arguments, so if the number of arguments dash LT less than one, so if the number of arguments is less than one, because we want at least one, then we're going to output a message that says input error, usage, the dollar sign zero says the name of the command, and then we're going to say we want an address. And then I'm going to give an example, and I'll show it here with single quotes, and then we're going to exit out. So we'll save that. We're on our script again. If we run it with an address, we're fine. If we don't give any arguments, we'll get that message saying to run it like this, here's an example. Let's go ahead and do it again, but we'll say, let's say Fifth Avenue, we'll say New York, New York. Hey, there we go. That's the GPS coordinates for 123 Fifth Avenue South and New York, New York. And that is our script. Now as I mentioned in the last tutorial, all my videos, all the videos in the series, all the scripts are up on my GitHub page. If you go to github forward slash metal x1000 and search my repositories for maps and locations, look under the bash folder, really, they're shell scripts, not specific to bash. I don't think anything I've done so far, but people recognize the name bash, so that's why I put it under. And this one was called gps.sh, and there's our code right there, you can download all these scripts, try myself. I recommend, if you're trying to learn, typing this all out yourself. If you have a problem that's not working, go ahead and download my script and run it. Just in case you have a typo of some sort, you can determine whether it's something wrong on your system, which shouldn't, this is a very basic script using stuff that should be on your system by default. But if you're having problems, go ahead and try my script. I recommend typing it out yourself, but they're all there, online, GPL code for you to use. So I hope you enjoyed the tutorial, I hope you enjoyed this series. If you're liking this series, if you like my videos, please like and subscribe and please share. That helps me out a lot, getting more viewers. As always, I hope that you have a great day, and I hope that you've seen my website, filmsbychrist.com, that's Chris the K, there should be a link in the description. And again, 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, Amber, 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 of my videos look something like this. And if that's what you're interested in, great. If not, that's alright. 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 ask 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 metalx1000. And I thank you for your time and your support. Have a great day.