Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9119089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:18:40+00:00 2026-06-17T05:18:40+00:00

I am trying to learn how to use the Google geocoding API but I

  • 0

I am trying to learn how to use the Google geocoding API but I cannot seem to make even the simplest example produce a map. I have searched on Google for alternative tutorials but everything seems in order.

Obviously I must be missing something. Here is what I have so far :

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=thisstuffisprivate&sensor=false">
        </script>
        <script>
            var map;
            var mapOptions;
            function initialize() {
                try {
                    document.write("Initialize entered");
                    mapOptions = {
                        center: new google.maps.LatLng(-34.397, 150.644),
                        zoom: 8,
                        mapTypeId: google.maps.MapTypeId.ROADMAP
                    };
                    document.write("<br>Map options created");
                    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
                    document.write("<br>Initialize exited");
                } catch (err) {
                    document.write("<br>Error: " + err.message);
                }
            }
        </script>
    </head>
    <body onload="initialize()">
        <div id="map_canvas" style="width:500px;height:300px;">
        </div>
    </body>
</html>

This produces a blank page. Note that I using this code on my computer and checking the results with Firefox. This is not hosted on an external server yet.

Can anybody help me figure out what mistake I have made ? This will enable me to continue learning how to use this API !

Thank you so much !

Edit:
– I have made a small test adding writes at the beginning and at the end of initialize() and it seems that it does not reach the last line (after the map creation) so it must be failing somewhere. Will try to investigate that.

  • Modified to take into account width and height. Thanks to Leftium.

  • After further testing, it seems to fail on the map creation step.

  • The code does not work on my computer on either IE, Firefox or Chrome but seems to work for other users. I am using Windows 8 and a relatively recent version of all browsers. Javascript IS enabled and I have tried turning off Windows Defender (just in case..). Still only a blank page.

  • I have also used an API key but it still produces a blank page.

  • I get the following output for the updated code above:

Initialize entered
Map options created
Error: a is null

  • It also produces a blank page on my Windows 7 laptop so it’s not an issue of compatibility with Windows 8.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:18:42+00:00Added an answer on June 17, 2026 at 5:18 am

    With further testing I found the exact error message and a solution on another SO question. Essentially, the problem is that the div is actually not fully built and the initialize() call searches for this element before it is in the DOM (please forgive me if the nomenclature is wrong).

    The solution is to move the call lower below creating the div.

    Google MAP API Uncaught TypeError: Cannot read property 'offsetWidth' of null

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to learn how to use the Google Spreadsheets API through the
I am trying to learn to use the wx packages to make GUI programs
I am trying to learn and use html5 and have a basic layout but
I'm trying to learn how to use the google app engine because I want
I'm trying use Google iosched as a reference project to learn the best practices
I am trying to learn to use mercurial by pushing onto Google code. I
I am trying to make a small application using the Google Maps API .
I am trying learn the use of lambda expressions and hence still struggling to
I am trying to learn and use an SDK for a vendor's product. Unfortunately,
I am trying to learn to use buffer overflow attack in Ubuntu. Unfortunately, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.