未调用地理编码回调

时间:2014-12-04 08:14:40

标签: javascript google-maps callback google-geocoder

我正在尝试使这个简单的代码工作。但似乎我无法进入地理编码 回调函数。 也许这是命名空间问题,但我找不到它?谢谢你的帮助

感谢您的帮助

这是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');
        }
    });

}

这里是测试页面

<!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>

1 个答案:

答案 0 :(得分:1)

最后找到解决方案。

实际上,问题不在脚本中,而是在HTML中。

我使用旧按钮<button></button>代替<input type="Button"> 它确实调用了函数,但由于我不知道回调函数没有使用地理编码函数调用

相关问题