Search code examples
javascriptgoogle-mapscallbackgoogle-geocoder

Geocode callback not called


I am trying to make this simple code work. But it seems that I cannot enter the geocode callback function. Maybe it is a namespace issue but I can't find it? Thanks for your help

Thanks for your help

Here is the javascript

/* routines for handling google maps */
var MAP_ROUTINES = MAP_ROUTINES || {};


/* find out coordinates in a map */
MAP_ROUTINES.coordinateFinder = function () {
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({ 'address': 'NYC'}, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            alert('Found');
        } else {
            alert('Not found');
        }
    });

}

here the test page

<!DOCTYPE html>
<html>
<head>
    <title>Googlemap coordinate finder</title>
    <meta charset="UTF-8" />
    <link rel="stylesheet" href="ressources/css.css" media="screen">



</head>
<body>


    <section id="search" class="shadow light_background col1 row2">

        <form name="search" id="search_form">

            <button id="go" onclick="MAP_ROUTINES.coordinateFinder()">Search</button>
        </form>
    </section>
    <!-- renderer -->
    <script src="http://maps.google.com/maps/api/js?sensor=false&amp;language=en"></script>
    <!--Script to handle google maps-->
    <script src="script/script.js"></script>



</body>
</html>

Solution

  • Found the solution at last.

    Actually, the issue is not within the script but within the HTML.

    I used the old button <button></button> instead of <input type="Button"> It did call the function but for a reason that I don't known the callback function wasn't called using the geocode function