未调用地理编码回调



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

感谢您的帮助

这是 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>

终于找到了解决方案。

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

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

最新更新