小编Ada*_*ley的帖子

如何等待谷歌geocoder.geocode?

请帮助我使用google geocoder.geocode.我知道这个函数运行异步,但我不知道如何处理它.

如何等待结果?这是我的代码:我的代码不等geocode.geocoder所以我得到undefined而不是geolocation.

<!DOCTYPE html>
<html>     
  <head>        
    <title>Geocoding service     
    </title>          
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />       
    <meta http-equiv="content-language" content="cs" />         

    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">            
    <link href="http://code.google.com//apis/maps/documentation/javascript/examples/default.css" rel="stylesheet">     
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>      
<script>

function codeAddress(callback) {   

  var address = document.getElementById('address').value;
  geocoder = new google.maps.Geocoder();
  geocoder.geocode( { 'address': address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
  } else {
      alert('Geocode was not successful for the following reason: ' + status);
    }
  },callback);  
}


function geocoder(result)  {
alert(codeAddress());
}

function button()  {  
  geocoder(codeAddress) ;
  } …
Run Code Online (Sandbox Code Playgroud)

asynchronous undefined wait

8
推荐指数
1
解决办法
7040
查看次数

标签 统计

asynchronous ×1

undefined ×1

wait ×1