0

我知道如何使用回调函数进行 bing 地理编码请求,如下所示:

function MakeGeocodeRequest(credentials)
         {
            var geocodeRequest = "http://dev.virtualearth.net/REST/v1/Locations/" + document.getElementById('txtQuery').value + "?output=json&jsonp=GeocodeCallback&key=" + credentials;

            CallRestService(geocodeRequest);
         }

         function CallRestService(request) 
         {
            var script = document.createElement("script");
            script.setAttribute("type", "text/javascript");
            script.setAttribute("src", request);
            document.body.appendChild(script);
         }
         function GeocodeCallback(result) 
         {   
            // Do something with the result
         }

(复制自msdn Maps AJAX Control 7.0 ISDK)

在 Bing Map 6.2 版本中,可以使用以下代码发出此类请求:

map.Find(null, tempDest, null, null, null, null, null, null, null, null,
                                function (a, b, c, d, e) {
...
});

这非常有用,因为所有变量都已定义并可以使用,但在新版本中,我的所有变量都未定义,我不想将它们作为全局变量,所以您知道如何在没有此类回调的情况下发出请求的任何解决方案吗?

4

2 回答 2

1

看起来版本 7 不支持 6.x 方法。这是 7 的示例。示例来自http://www.bingmapsportal.com/isdk/ajaxv7#SearchModule2

刚刚添加了警报(topResult.location);行,以便您查看位置信息。

function geocodeRequest() 
{ 
    createSearchManager(); 
    var where = 'Denver, CO'; 
    var userData = { name: 'Maps Test User', id: 'XYZ' }; 
    var request = 
    { 
        where: where, 
        count: 5, 
        bounds: map.getBounds(), 
        callback: onGeocodeSuccess, 
        errorCallback: onGeocodeFailed, 
        userData: userData 
    }; 
    searchManager.geocode(request); 
} 
function onGeocodeSuccess(result, userData) 
{ 

if (result) { 

        map.entities.clear(); 
        var topResult = result.results && result.results[0]; 
        if (topResult) { 
            alert(topResult.location);
            var pushpin = new Microsoft.Maps.Pushpin(topResult.location, null); 
            map.setView({ center: topResult.location, zoom: 10 }); 
            map.entities.push(pushpin); 
        } 
    } 
} 
function onGeocodeFailed(result, userData) { 
    displayAlert('Geocode failed'); 
} 

if (searchManager) 
{ 
    geocodeRequest(); 
} 
else 
{ 
    Microsoft.Maps.loadModule('Microsoft.Maps.Search', { callback: geocodeRequest }); 
}
于 2013-12-29T04:53:25.533 回答
0

在 url jsonso参数中指定。示例: var geocodeRequest = "http://dev.virtualearth.net/REST/v1/Locations/" + document.getElementById('txtQuery').value + "? jsonso=paramValue &output=json&jsonp=GeocodeCallback&key=" + credentials;

于 2011-08-05T08:02:52.570 回答