【问题标题】:synchronous request google maps geocoding同步请求谷歌地图地理编码
【发布时间】:2016-03-08 09:00:21
【问题描述】:

我们如何同步以下请求。因为它默认是异步的。

 $.getJSON('http://maps.googleapis.com/maps/api/geocode/json?address="'+address[x]+' '+zipcode_true[x]+' '+city[x]+' '+state[x]+'"&sensor=false',null,function (data) { 
            var p = data.results[0].geometry.location;

  var latlng = new google.maps.LatLng(p.lat, p.lng);
 var latlng_marker = new Array();
 latlng_marker[x] = latlng;  
});

【问题讨论】:

  • 但是为什么呢?这种异步性质似乎是更好的选择。

标签: javascript geocoding


【解决方案1】:

这应该相当于下面的同步代码:

var data = $.ajax({
    url: 'http://maps.googleapis.com/maps/api/geocode/json',
    method: 'GET',
    async: false,
    data: {
        address: address[x] + ' ' + zipcode_true[x] + ' ' + city[x]  + ' ' + state[x],
        sensor: false
    }
});

var p = data.results[0].geometry.location;

var latlng = new google.maps.LatLng(p.lat, p.lng);
var latlng_marker = new Array();
latlng_marker[x] = latlng;  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-29
    • 2011-08-28
    相关资源
    最近更新 更多