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

  • SEARCH
  • Home
  • 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 8262563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:47:44+00:00 2026-06-08T03:47:44+00:00

Am pulling my hair out trying getting GeoCoder working. I went so far as

  • 0

Am pulling my hair out trying getting GeoCoder working. I went so far as to just pull the example straight from Google and pasting into my HTML but it still doesn’t work. Here is the code.

The address I capture from my field gets passed back into the geocoding function fine. Everything logs out to my console. But the map just refreshes and nothing happens.

I uploaded the code to my site as well. http://voidkat.com/geo/index.html

Please help!!

Google Maps Multiple Markers

Address:

              <div id="map" style="width: 500px; height: 400px;"></div>

              <script type="text/javascript">
                var geocoder;
                var map;
                var address;
                  function initialize() {
                    geocoder = new google.maps.Geocoder();
                    var latlng = new google.maps.LatLng(-34.397, 150.644);
                    var mapOptions = {
                      zoom: 10,
                      center: latlng,
                      mapTypeId: google.maps.MapTypeId.ROADMAP
                    }
                    map = new google.maps.Map(document.getElementById("map"), mapOptions);
                  }

                  function codeAddress() {
                    e.preventDefault;
                    var address = document.getElementById("address").value;
                     console.log(address);
                    geocoder.geocode( { 'address': address}, function(results, status) {
                      if (status == google.maps.GeocoderStatus.OK) {
                        map.setCenter(results[0].geometry.location);
                        var marker = new google.maps.Marker({
                            map: map,
                            position: results[0].geometry.location
                        });
                      } else {
                        alert("Geocode was not successful for the following reason: " + status);
                      }
                    });
                  }
              </script>
            </body>
            </html>
  • 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-08T03:47:46+00:00Added an answer on June 8, 2026 at 3:47 am

    You need to put onsubmit onto the form, not onclick on the button.

    Also, to call a function, you must put parentheses after it, even if it doesn’t accept parameters, so it would be e.preventDefault(); not e.preventDefault;. And in the case of onsubmit (or any on), events cannot be canceled inside the function, you must use onsubmit="event.preventDefault(); ...".

    Demo: http://jsfiddle.net/eEEpj/

    Code:

    <!DOCTYPE html>
    <html>
    <head>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
      <title>Google Maps Multiple Markers</title>
      <script src="http://maps.googleapis.com/maps/api/js?sensor=false"
              type="text/javascript"></script>
    </head>
    <body onload="initialize()">
        <form id="addressForm" onsubmit="event.preventDefault();codeAddress();">
            <div>
            <label for="address">Address:</label>
            <input type="text" name="address" id="address" />
            <input type="submit" id="addressButton" value="Get Coordinates" />
            </div>
        </form>    
    
      <div id="map" style="width: 500px; height: 400px;"></div>
    
      <script type="text/javascript">
        var geocoder;
        var map;
        var address;
      function initialize() {
        geocoder = new google.maps.Geocoder();
        var latlng = new google.maps.LatLng(-34.397, 150.644);
        var mapOptions = {
          zoom: 10,
          center: latlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        map = new google.maps.Map(document.getElementById("map"), mapOptions);
      }
    
      function codeAddress() {
         var address = document.getElementById("address").value;
         console.log(address);
        geocoder.geocode( { 'address': address}, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location
            });
          } else {
            alert("Geocode was not successful for the following reason: " + status);
          }
        });
      }
    
        /*
        //de infowindowz
        var infowindow = new google.maps.InfoWindow();
    
        //de markers
        var marker, i;
    
        //de locationz
        for (i = 0; i < locations.length; i++) {  
          marker = new google.maps.Marker({
            position: new google.maps.LatLng(locations[i][1], locations[i][2]),
            map: map
          });
    
          google.maps.event.addListener(marker, 'click', (function(marker, i) {
            return function() {
              infowindow.setContent(locations[i][0]);
              infowindow.open(map, marker);
            }
          })(marker, i));
    
        }
        */
      </script>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been pulling my hair out trying to use jQuery.get() to pull in my
I'm pulling my hair out trying to get a jQuery script working that will
I'm pulling my hair out trying to figure out why the mouseover event won't
I have been pulling my hair out trying to figure out what I can't
Ive been pulling my hair out trying to figure out how to embed a
I have been pulling my hair out trying to make this work. I have
Hey Apple developers, I'm pulling my hair out trying to figure out how iOS
I'm pulling my hair out here trying to get CSS to position only a
I've been pulling out my hair trying to figure this problem out. I have
I have been pulling my hair trying to figure this out but nothing is

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.