0

My page should show a single Google Map.

If I throw the code in a JSFiddle, it works fine.

All of my files are in the same directory. I tested in Chrome and Firefox, both don't show the map. So I think there must be something about the way I am calling for access to my JavaScript and CSS.

HTML

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="bob.css">
        <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
    </head>
    <body>
        <h1>My Heading</h1>

        <div id="map"></div>

        <p>My paragraph.</p>

        <script type="text/javascript" src="bob.js"></script>
    </body>
</html>

bob.js

var mapOptions = {
    center: new google.maps.LatLng(37.7831,-122.4039),
    zoom: 12,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};

new google.maps.Map(document.getElementById('map'), mapOptions);

bob.css

html, body {
  height: 100%;
  margin: 0;
}

#map {
  height: 100%;
  margin: 0;
}

Console output

JavaScript Console

4
  • 2
    Are bob.css and bob.js in the same folder as bob.html? Commented Jul 17, 2013 at 12:34
  • @JeremyGallant Yes, they are. Commented Jul 17, 2013 at 12:38
  • 1
    @Bamgag Filenames are case-sensitive. Did you make sure the files are all written in lowercase, just like in your code? Commented Jul 17, 2013 at 12:42
  • @JeremyGallant That is a good thought but my files are, in fact, all lower-case just as they are written in the html file. Commented Jul 17, 2013 at 12:48

2 Answers 2

1

Perhaps the server is (mis)configured in some way so that relative paths don't work. If your files are in the root directory, then an absolute path won't hurt.

Try:

<link rel="stylesheet" type="text/css" href="/bob.css">
<script type="text/javascript" src="/bob.js"></script>
Sign up to request clarification or add additional context in comments.

4 Comments

The files are in the same folder. What explanation would justify the use of /, everything should be working fine without them anyways.
Did it work with /? Perhaps the server is (mis)configured in some way so that relative paths don't work. If your files are in the root directory, then an absolute path won't hurt.
I'm not the OP. But the explanation you just added should be a part of your answer ;-).
Could you give us the url you are developing on?
0

I tested both on firefox and chrome, both work smooth. I assume you are testing this on a site so (as Johan Bouveng said ) there could be something worng, so i would try this instead:

<link rel="stylesheet" type="text/css" href="./bob.css">
<script type="text/javascript" src="./bob.js"></script>

./ to point to the exact same directory of the calling file ( in this case bob.html )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.