2014-12-04 62 views
0

我想使這個簡單的代碼工作。但似乎我無法輸入回撥功能的地理編碼 。 也許這是一個命名空間問題,但我找不到它?感謝您的幫助不叫地址碼回調

感謝您的幫助

這裏是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

找到了解決辦法,最後。

實際上,問題不在腳本內,而是在HTML內。

我用老的按鈕<button></button>而不是<input type="Button"> 它確實調用函數但是,我不知道的回調函數的理由使用地理編碼功能

+0

形式內的按鈕不叫是造成要發佈到服務器的表單,重新加載頁面並中止地理編碼請求到Google的服務器。 – geocodezip 2014-12-04 14:56:27

+0

這真的幫助了我!謝謝 – Andrew 2017-12-09 07:45:10