 Again, this is a series, this is the third in the series, I recommend watching the first two firsts, hopefully there's an annotation somewhere in this video that will bring you to the full playlist, if not check the description. And this week we're going to be looking at grabbing a map based on an address from a shell script, a bash script. Now we're going to be using the Google API, unfortunately it's not fully open, the maps are going to be copyrighted, but right now we're basically using it as a service, all the code that I write is going to be free and open source, but remember you're using a service someone's providing, they can change or take away that service at any time. That's up to you, there is open street maps which we could probably do similar stuff with, I'm just used to using Google maps, open street maps might be something you want to look at depending on your moral, ethical and technical views and your needs, I just wanted to get that out of the way. So today we're going to be using WGet to grab a map and then we're going to grab it as an image, as a still image, as a static map and we're going to then display it on the screen to display it, I'm going to use the command display which is part of the image magic package, image magic is installed on a lot of systems but not necessarily all systems by default but should be in your repositories, so example on a Debian based machine you can use aptitude or apt get to install image magic right there, like so probably as sudo or root, I already have it installed, you might already it's commonly used, so let's go ahead and again I'm going to use WGet, you could use curl if you prefer, I'm going to say dash O and I'm going to give it an output file, so in previous videos we were outputting to the screen because we were getting text but this time we're getting a binary file and image and so we want to make sure that we output that, so we're going to say output that to a file, I'll just call it map.png because I believe it's png, it's png format that Google Maps gives us, we can then give it the URL but I'm going to do dash Q, if you have any problems remove the dash Q, the dash Q gives you output as far as download speeds and percentages and stuff like that, it's good for error checking but in our scripts I'm going to leave that, I'm going to put the Q in there just to keep things cleaner, so now I'm going to paste a URL in there, let me go ahead and copy that and I will paste it, so again we're using the Google API here and you can leave the S in there for secure, I'm going to go not just to avoid any issues we might get, so I'm downloading it unencrypted, not a big deal for something like this, Maps GoogleAPIs.com Maps API static map and then we've got to give it some arguments and inputs, so I'm going to say question mark and I'm going to say center, where do we want to center the map, center it, now we're going to give it an address, again just say one, two, three, fifth avenue of south, Naples, Florida, I live in Naples, Florida and if we enter at this point we're going to get a problem because we need to tell what size we want map, those are the two minimal arguments you need to give it, so size and this is the size of the image that we want to create, so I'll just say 512 by 512, those give us a square map 512 by 512 pixels, so I'll go ahead and hit enter and if we list out now you can see that I have a file in this folder called map.png and if I type in display because I have image magic installed, the name of that file there is the map, it's that simple to get a static map, obviously you can't drag this around, it's a still image, it's a static map, future tutorials will get into using JavaScript to get interactive maps, but for shell scripts, static maps are probably the easiest way to go and there's other arguments you can give it as well which we're going to look at right now, so the next thing we want to do is how close do we want to zoom in to the map, so let's go ahead and run that same command again, wget and what I'm going to do is I'm going to say end and that means if the last command completed successfully, then we will display map.png, go ahead and enter there and look at that, let me check something real quick, okay just making sure it didn't create a new map file and then we're looking at the old one, okay so again wget is a command to download stuff from the internet dash O, that's not a zero, it's a capital O is the output file we want to output to a map png and then we'll say dash Q for quiet mode, you turn that off for troubleshooting and our URL saying size and we're saying end and if that is successful, if not don't try to display the map, but if it's successful then display the png, okay so now we're going to give it another argument here, we'll say end and we're going to give it the zoom amount, so we'll say zoom equals and the higher this number, the closer you zoomed in, I'm not sure what the max is, I think it's in the 20s somewhere, but and I think the default, I forget there is a default obviously because we didn't give anything, I want to say it's 11, so let's go ahead and let's just try doing 20, that should bring us pretty close in on the map, there we go, we're looking at Fifth Avenue South and you can see some buildings there, but we're again, we're just looking at a street view here, our street view, a satellite view or a map view, a roadmap view, but there are other options, there's terrain, there's satellite or what I like is the hybrid mode which is satellite view with the map, the roadmap view over top of it, so we're gonna say here is we're gonna give it another argument and these arguments don't have to go in this order, you know, if you're familiar at all with passing variables to arguments to URLs, we're going to now say type, I'm sorry it's actually map type equals and I will just say high bread or high breed, how are you saying it, enter there and there we go, you can see the map information saying the street name, you can see the buildings, you can see what it looks like, you can see cars on the road, great, let's zoom out a little bit, let's go back to maybe 15, well that's pretty far out, let's go back in and we'll say 18, there we go, so there we go, I'm not sure the max resolution, I don't think it's much higher than 512 by 512, that's something I should have looked up before this tutorial, but for what we're doing, this is pretty decent here, we've got our street view, our high bread view, our street view with the map view over it, so we have the road names, we just did satellite, I don't think it gives the street names and that's something you might want, if you don't want street names, just do satellite view, you will always get the Google copyright information down here because it is a copyrighted image, you could cut that off but that would probably be illegal, again, my script is free and open source but doesn't mean the information you're grabbing from the internet is free and open source, okay so let's put all this into a script and to save us time, I'm going to pop copy and paste the script I've already created, so let me go ahead and I'll say I'm gonna use Vim as my text editor but as always use whatever text editor you prefer, I'm gonna say getmapaddress.sh and then I'm going to go ahead and come over to my other screen here and I'm going to copy and paste that, I also want to point out a lot of people complain about my color coding and then I use a black background in my tutorials, I want you to note that I did change the color scheme and I think it's a little bit easier readable now, the colors a little bit brighter on the black background, I hope that makes you guys happy, okay so let's go ahead and look at this script, so I have some comments with some example coordinates here, we got a echo out saying retrieving map which really probably should be put down here, let me go ahead and move that, I think that would be better sued down here, otherwise we'll say retrieving map and then it might give you an error output before you even start to retrieving the map so let's go ahead put that there, so what we got here we got okay if you watch the previous tutorials you know what this is, this is saying how many arguments are there if there's less than one because we want to give it at least an address then give it the use of the output so we're gonna say okay input error if there's less than one argument and we're gonna say okay use it like this give it the address type and zoom amount, you only need to give it an address but type and zoom amount are good to have, so here's an example and then here we're gonna say examples of of map types I just put a few I'm not sure if there's others those are the four I'm familiar with road map terrain satellite and hybrid default in my script is hybrid and then we'll exit there so that's if you don't give an address if you do get an address gonna say retrieving map and really technically that should be down here but it shouldn't fail at any point in here because what this is doing is putting in the defaults so as I said in my script is gonna say okay argument one should be address argument two should be type of map and argument three should be the amount you want to zoom so again zoom is number three it's gonna say here if three is blank if the user does not give a zoom amount let's go ahead and default to 15 that's my default otherwise use whatever the user gives same for argument two if the user does not give an argument two then we're gonna default to hybrid otherwise we're gonna use what the user to says you might be saying well what if I want I don't care about putting type I want put in the zoom my script I'll show you a way to use that with my script there's better ways to get arguments I'm just doing what I know that's when I look at the first argument and make that the address and then we're gonna put the output into a file here a randomly generated temporary file in this in this case so here we have pretty much the same code we have before but placing in our variables we're saying you know get the address with all that information and then output it to a random file and then display that random file really I should be using that end-end symbol because if that fails then we don't want to try to display it but I didn't put that in my code so I could put that here I and like so but whatever anyway we're gonna play and after we display it when we're done displaying it we're gonna remove that temporary file so that's what so this is this is really the majority of the code here the rest is just getting information from the user let's go ahead save that change mod plus x to make it executable then we'll say get and again if we hit enter here we get our message here and let's go ahead and just type in the example we'll copy and paste the satellite at 15% zoom of 123 Fifth Avenue New York and it's gonna guess which half Fifth Avenue so I'm assuming there's probably North and a South it's gonna grab whichever first one comes up in the Google search and that did not work okay let's see what we got here obviously I typed something wrong unable to open oh I must have let's go ahead and this is a oh oh I put an eye there I was exit when I was putting stuff in I put an extra I messed up my variable there I'm like a copy and pasted this script I know that works okay let's try running it again retrieving map there's Fifth Avenue in New York at a 15% zoom satellite view so there's no street names so we can go here if we were to clear out the screen and run it again let's say I want the 15% zoom but I don't care I don't want I just want to be hybrid I can type in hybrid which default but I let's say I just want the default I could just put an empty you know argument there either with double quotes or single quotes doesn't matter and we'll do the hybrid mood so you see mode so you see we've got the satellite we got the hybrid the satellite with some names mapping stuff on it we can now zoom in more if we want 20 which is pretty close oops I just closed out my shell let's go ahead and open that up again maps okay so again our scripts creating a random temporary file in our template and deleting it this map is from when we were doing the examples earlier so let's go ahead and let me just open this up again and that's pretty much it for this tutorial thing about going over the code again but I've kind of gone over everything but if you want if you have any questions here is my github repository for this if you go to github.com forward slash metal x1000 my name is metal x1000 on github and you search my repositories for maps and locations you'll find my maps locations under bash you can find all the scripts in this series this one was called which one was this this was the get map from address right here so you click on that see that code you can download the whole project or the raw individual codes so that's all up there for you to look at I recommend typing it out yourself to learn and practice but if you're having issues go ahead and download and run my script should work everything but image magic should be installed on your system by default image magic should be in the repositories for your system I think it's on all of them if not change what program you use to display the image that's it for this tutorial I hope that you enjoyed it I hope that you have a great day I hope that you like and share and subscribe this video definitely liking and sharing definitely helps me out a bunch getting more viewers I hope you visit my website filmsbychrist.com that's Chris with a K there should be a link in the description check out the annotations in the description for a full playlist for this series 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 of 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 we 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 metal x1000 and I thank you for your time and your support have a great day