Troubleshooting Google Map
Troubleshooting Google Map
Video Transcript
00:00Our next step will be to create an actual map. To create the map, again, we'll be using the same things that we've done in a previous example.
00:07So we're just going to do it really quickly. I'm just going to create a new variable and I'm going to call it map.
00:12Once I create the variable, I want to set it to be a new google.maps.map.
00:18Now, I'm going to ask if it has its first parameter to let it know what div layer I actually want to put it in.
00:23In our case, if you recall from earlier, our HTML itself has a node, an empty div layer, which is called map.
00:30So we're going to explicitly ask Google Maps to live inside of there.
00:34To do that, I'm going to go to my document and I'm going to get an element by ID.
00:38And by the way, this is an HTML5 method.
00:41If you're trying to build your application to create an application that does not contain it, then it would not work for you.
00:47So you'd have to use a different method of fetching information such as using jQuery or any other solution where you don't have to approach directly the APIs of HTML.
00:57In our case, we're approaching directly the getElementByID, which is an HTML5 method, which means if you have a browser that doesn't support it, this is where your application would break.
01:07So I'm going to load in that map itself and I'm going to get that map back.
01:11Once I get the map, that would be the first parameter that I send to our map.
01:15The second parameter is going to be our object that holds inside of it all the different various information that we want to set to our application.
01:24For one, we want to make sure that its center point is that new center point, which is going to be our lat-long.
01:29That is enough for us to be able to build our application.
01:35All we have left to do is just close this baby up.
01:38We're closing the same line.
01:40Close this opening and closing round bracket.
01:43Make sure that our application is set.
01:45We can see that there are no errors.
01:47It's time for us to go back into our browser.
01:49Once in that browser, we can go back into our application that we're working on and click on refresh.
01:53We should be seeing a Google map there somewhere pop up if we've done everything correctly.
01:59Now, very high probability that we didn't, obviously, because we're not seeing that Google map.
02:04Let's see if we can sort it out somehow.
02:06First of all, what I want to do is I want to make sure that we're actually getting all the way here.
02:10To do that, I'm just going to go to this element and I'm going to go to my console.log.
02:15I'm going to tell my log file, rendered, no issues.
02:20Just make sure that it's inside of a string.
02:22I already have a feeling I know what the issue is, but I'm not going to show it until we know it.
02:27Because one of the things that we want to do while we're learning in our site zero2kink in general
02:31is to learn from our mistakes and beyond that learn and understand how to fix them.
02:36First of all, we can see that we're not finding any errors, which is a good sign.
02:40That means everything seems to be okay.
02:42Our only problem is we can't see it.
02:44The highest probability is that our div layer isn't set to be seen.
02:48It might be in a position.
02:49It might be set to zero, zero by default.
02:51Google just is rendered, but we just can't see that it's rendered.
02:54To check if that is true, we'd want to go back into our Dreamweaver.
02:59Or even if you have a Firebug or an application similar to Firebug,
03:03you could actually go to that HTML, find that div layer,
03:07and just look inside of it and see if you have things inside.
03:11And we definitely do.
03:12There's stuff going on inside.
03:14So the next step that we could do is if we're working with an application such as Firebug
03:19or any other debugger where you could view the HTML directly,
03:23we could add your width of 100 pixels.
03:26We could add your height of 100 pixels.
03:28And we could see if it's changing anything.
03:30And look and behold, we could see that it definitely is.
03:34Now, if I change the height to be 1,000
03:36and I change the width to be 1,000, we might be able to see even a lot more.
03:40And now we can see that we definitely have something going on,
03:43but unfortunately, because we set our div layer to be so small,
03:46we can't see anything.
03:48All right, so our highest probability is that if we render our application
03:52in advance when our application begins
03:54and we give it the amount of room it needs to be able to render a map,
03:57then our map will render.
03:59So we're going to go back right into our Dreamweaver.
04:01And in our Dreamweaver, we're going to hop back into the HTML file
04:04and just add directly some CSS into that file.
04:08So to do that, first of all, we're already going to clean our elements up
04:12very much so.
04:13So I'm just going to go all the way to the top here
04:15and I'm just going to create a new style file.
04:17And I'm not going to take it out just because we're just focused
04:21on JavaScript right now and not on CSS.
04:23Ideally, you probably would want to put it into an external file,
04:26especially if you're going to be using it over and over in other places.
04:30In our case, we're really building this page only for this page.
04:33We don't really care. We are living on the edge.
04:36So what I'm going to do only is I'm going to create a new rule
04:39for the map ID that we have.
04:41And this rule is going to be very, very simple.
04:43I want to set it to be as a height of 100%.
04:47I want to set it to a width of 100% as well.
04:52I want to also position it to be absolute.
04:57And I'm going to absolutely position it all the way on the top,
05:00making sure that we don't have any extra margins of any sort.
05:04And I'm going to set that to be at 0px at the top itself,
05:07making sure it's right there in the top.
05:09Now I want to add a couple of things also for formatting.
05:12So I'm going to go to my body itself,
05:13and I want to make sure that my body itself
05:15takes the full length of the screen.
05:17So I can even copy this height and width for my body as well.
05:22And I could copy this and save this.
05:25And once we do that, we could go back into our HTML
05:27and hopefully we'll build a CR map rendering on our whole screen.
05:31And that we do see only we're not seeing a specific map right now,
05:34which is obviously a little bit sad.
05:38But we are definitely getting warmer
05:39because now we could see that our layer is actually
05:41loading in the whole area.
05:43We're having here a little bit of loading issues,
05:45so I'm going to give it a chance to load.
05:48Might be some sort of connection issue of some sorts.
05:51I'm going to stop talking.
05:53Hello.
06:02So we're back.
06:03Our computer crashed.
06:04Well, that computer, the browser crashed,
06:06so I went and got myself a cup of tea.
06:08In the meantime, it's Chai.
06:11For all of our friends in India, I love Chai.
06:14We actually have a lot of students in India,
06:16and I really admire you guys for working hard
06:20and joining our school.
06:21It's really cool and very uplifting
06:23to see you guys in our school.
06:26But back to what we're talking about.
06:29So we were talking about Google Maps.
06:31We were trying to build our application,
06:32but we got stuck somewhere.
06:34And our browser even crashed.
06:36So literally, where we left off was,
06:38we got ourselves into a jam.
06:40Our map is starting to see that we don't have any errors,
06:43but we could see that our map is rendering,
06:45but we can't see it.
06:47We made our space larger,
06:49and now we could see the space
06:51where the map is supposed to be.
06:52If you zoom in really closely to the edge,
06:54you'll see that we have an offset
06:55that we'll want to fix a little bit later.
06:58But before we fix it, let's get that map in.
07:00Now, the only thing that's missing,
07:02although Google now knows that it needs to be in the center
07:04because we set it to be that specific spot in the center,
07:07it doesn't know what it needs to show.
07:09So two things we want to tell it.
07:10We want to tell it, first of all,
07:11what zoom level we want our map to be in.
07:14To do that, it's really, really simple.
07:16All we have to do is just basically type in the zoom level that we want.
07:19There's a few layers,
07:20a few different configurations of zooming.
07:23But we'll start with the basics.
07:25We'll start zoom.
07:26We'll zoom at seven,
07:27and we'll play with the parameters
07:28to show you the different things you could play with,
07:31a little bit of it.
07:33Now, the next thing is going to be the map type.
07:35There are a few different map types.
07:36There's a hybrid, there's a roadmap,
07:39and there's a satellite.
07:40And for our case and scenario,
07:42I would love to use the satellite
07:43because it's the most pretty picture out there.
07:47Now, all the map types are sitting in the same,
07:49it's basically a string that we send in,
07:51but we use map type.
07:57And it's a string that we use,
07:58so I'm going to type your google.maps.map.
08:02Type id.
08:05The type that we want.
08:06Now, by the way, it's a string.
08:09So we could have typed the string indirectly,
08:11but what's nice about using these constants,
08:13which this is exactly what that is,
08:15it's a constant that holds inside of it the information.
08:18So we could have put a satellite,
08:19we could have put a hybrid,
08:20or we could have put more,
08:23which the other one which was,
08:24was, was, was, was, was roadmap.
08:27So in our case, we want to use satellite,
08:29we want the zoom level to be seven.
08:30Once we do that and we refresh our application,
08:33we shouldn't be getting our map,
08:34and it should be a little bit offset
08:35from where we would want it to be.
08:37Now, if we don't get the map,
08:39the most probable scenario is that we have
08:41some sort of error here,
08:43and it's the most logical, probable, immediate thing.
08:46So what I'm going to do is I'm just going to copy,
08:48making sure again that I type it exactly
08:50the way it's supposed to be.
08:52And I'm just going to type it in here.
08:54And again, map type id,
08:55which for some reason got deleted.
08:57So map type id, not map type.
08:59And I'm just going to, for roadmap,
09:01we could refresh it,
09:02and we should get our roadmap of Google right here.
09:05But really what we want is the satellite.
09:07So instead of that,
09:08we will click on first satellite.
09:10That would be S-A-T-E-L-L-I-T-E.
09:14I'm going to save that,
09:15go back to my application,
09:16and I should now see a nice zoomed-in
09:19area of the world,
09:20which was previously in a roadmap.
09:23And that covers our map basics.
09:27But before we continue on,
09:28I really want to set our position more correctly,
09:30because as you can see right now,
09:31we have here a bit of a problem.
09:35As we have a horizontal scroll and our map is offset,
09:39really what we want to do is push our map right to the edge.
09:42To do that, I'm just going to go back into my source files,
09:44back into the HTML.
09:45I'm going to delete that width of 100%.
09:47There's no need to say that twice.
09:50And instead of that,
09:51I'm going to make sure that my margin is zero.
09:54As zero pixels.
09:56And I'm going to make sure that there is no padding as well.
09:59And we want to make sure that padding is zero pixels as well.
10:04I think that should do the trick,
10:06but if it doesn't, we will do a little bit more tinkering.
10:08So I'm just going to go back into my map.
10:10I'm going to refresh it,
10:11and I should see my map now snapped right to the spot
10:14where it needs to be.
10:15And we can see now Oto that we don't have any horizontal
10:18scrolling or any other type of scroll that we don't want.
10:22All right, so before we move any further,
10:25our next step will be, that's it.
10:28We got ourselves a map.
10:29It's up and running.
