02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Using SpreadSheet to Control Map

Using SpreadSheet to Control Map

Video Transcript

00:00My chai is almost done and it's time for us to get more serious in our recording
00:04So let's continue digging deeper into our data
00:07And I'm just gonna delete a little bit of the commenting because we don't need them really anymore
00:12And you'll have a copy of that in the source files if you download them, but we don't have any use for them
00:16So let's just clean things out up a bit. I like clean space and
00:20Going back into our on sheet callback, which is really where we want to work
00:24Is where we want to start creating things and by the way now that we're here really the importance of having the queue in our application
00:32Has no meaning because our queue itself is just a query. What we really want is the response
00:37We want to save the response we care less about saving the actual query itself because once we get it we're done with it
00:43Alright, so now that we have our response back
00:46The first thing I really want to do is I want to save that response so to do that
00:49I'm gonna save that into the data object which will contain our response and
00:53More over than that. We're not only gonna save the response itself. We want to really save that specific thing in the response
00:59So before we dig deeper, let's look into our object itself that comes back and I already did this for us earlier
01:07But really in in this object itself and you could trust me here on this one or you know
01:11I could show it to you. Alright, so first of all in our console log we could log that response
01:17But instead of logging that full response
01:19What we want to do is we want to go inside of the object itself and literally in your case
01:25You might want to search for it. Oh
01:27Here you all right. So our response has an object inside of it, which is called dot G
01:33And in that G which probably stands for Google
01:36There's an element which is not me in uppercase very weird, but very true
01:41Now if we go and reload our application
01:44We will see that when we get our response back
01:47We're gonna get our object that contains actually all the information that we need that is the information inside of our spreadsheet
01:54now
01:54This is the best time to remind you again that
01:57Apis change and now that we're digging deep into the API because I personally just don't want to work with the exposed API
02:03I want to work with the direct objects
02:05What you would want to do is make sure that your version will not be one dot zero
02:09But the actual version of what you're in for the visualization IP API
02:14To make sure that even if Google changes the API you could still work with the older variation making sure that if they change stuff
02:20It's not gonna affect your code and we'll look at that later
02:23But for now we're gonna keep 1.0 and we're gonna continue stepping forwards and continuing building our application
02:29So now that we know our object is that response that G dot D and uppercase
02:34I'm gonna save that information and we could always use the console to search for it
02:38But once we found that object our next step would be probably to try to trigger and find out our first parameter
02:45We're in our first parameter. We have a long lag longitude and a latitude and longitude and a zoom level
02:51We would love to fetch that information
02:54Now to fetch that information we would have to dig a bit deeper into the object that returns
02:59So let's first really literally just trace out not the whole thing, but just trace out the first element
03:05Once we trace out the first element, we'll be able to look more deeply and by the way just to make this more pretty
03:10We could do this after we set our data
03:13globally in our application and then approach our
03:16Map itinerary data object and fetch that position zero to understand what's inside of it
03:22Once we do that we could refresh your application
03:25Wait for the element to come back and then open it up and really dig into that object
03:29so first of all, we could see that we have an object that's called C and
03:32Inside of that object. We have a position zero which holds our leg our latitude and then we have our
03:39Wonder this is our longitude and we have three which is our zoom level and we have two that which is our zoom level and four
03:46Three which holds our information and so on and so forth. So we know that inside of object C in
03:52Position zero one and two we have all the information we need to start creating here some interesting things
03:58So let's test this out
03:59what I want to do is go back into our application right here and what I could do is maybe call a new method of our
04:06Map itinerary and just force it once the data is set to basically show us that specific first spot
04:14So let's call this this dot
04:16go to
04:18Points go to points and in the go to point method
04:22We could just send inside this new object knowing that our point itself that C because the object inside is called C as we just saw
04:30in the API
04:31We don't need to call
04:34our
04:35Log anymore, but what we do need to do is create that method
04:38So I'm gonna again create a new prototype because we want this to be publicly available because we're gonna add more
04:44options to it and we're gonna go to point and
04:48in this point and maybe go to
04:51Go to row maybe and the reason why I'm changing it to row is because a point is
04:59Literally a point and we don't want to get confused between a point and maybe a row in our
05:05spreadsheet so just to make it more explicit because we might want to use a go to
05:08Point at some point no pun intended. So go to row will now have a function and that function will accept one parameter
05:16which is going to be the
05:18row information and
05:21That row
05:22Information will be rowing and we'll put here of equals to make sure that it's not giving us errors and inside of this
05:29It's time for us to start manipulating our map
05:32So I could go directly to our map dot this dot map because our map is stored in our object
05:37And once we're in the map itself
05:38We could now start sending it to do new things such as changing its center point
05:43Now to change the center point in a map is not that hard
05:46All you have to do is actually call the set center function. So set center and once we call the set center
05:52We want to put a new lat long
05:54Position so to do that I could create right inside there a new google dot
05:58maps dot lat long and
06:02Send our lat new lat long information, which we discovered which is in row zero if we look at it again
06:08we'll see that we're in row zero and
06:10V for vector, so it's going to be zero dot V
06:14And we're going to do the same thing otto or vertice or whatever word it actually means and
06:20Position zero and position one should in theory
06:24Be all we need to reset our map to go to a new position once we got our information
06:29So let's see if we refresh our application in theory and hopefully more than just theory our map will automatically reset and move to the first
06:36Position which is the position of Jerusalem now
06:39The only problem that we have left right now is we're not actually changing our zoom level as well now looking for us
06:45There is always a way to zoom and change our properties now to do that
06:51We would do the exact same thing with our set center, but instead of set center
06:55We would call it this dot map dot zoom or set zoom and our set zoom
07:00We would be able to call again letting it know explicitly what we want to do which we would call that specific row
07:06Which is going to be in row two and row two. We want to get that V that dumb value
07:11That's not a string literally the number versus the string and that should in theory zoom us in as well
07:18So we'll be able to jump right in
07:20To this specific region that we want and we'll see that specific region zoomed in in the position that we want it to be
07:27Now if we want to make things more interesting, which I guess we do
07:30It would be really fantastic if we could show where we actually are
07:34Originating from and maybe each time that the user clicks on the position that we are on
07:39It will show us the next position where we were going to be going to and that's what really we want to build here into
07:45This application. So so far we've passed through the combination of our data
07:49And now we're even going to a specific row without any specific animation
07:53Our next step right now, which would be really really useful would be to add a new marker point
07:59That would go directly exactly where the marker is supposed to be with a little bit of information of what's inside that specific marker

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!