Bing地图,如何在7版本中发出地理编码请求而不回调?

发布于 2024-11-18 01:44:38 字数 1108 浏览 3 评论 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) {
...
});

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

I know how to make bing geocode request with callback function, like this:

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
         }

(Copied from msdn Maps AJAX Control 7.0 ISDK)

In Bing Map 6.2 version it was opportunity to make such request by using the next code:

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

It was very useful because all variables were defined and ready to use, but in new version all my variables are undefined and I do not want do them as global, so do you know any solution how to make request without such callback?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜心小果奶 2024-11-25 01:44:38

看起来版本 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 }); 
}

Looks like version 7 doesn't support the 6.x methods. Here's an example for 7.
Example is from http://www.bingmapsportal.com/isdk/ajaxv7#SearchModule2

Just added the alert(topResult.location); line so you see the location info.

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 }); 
}
a√萤火虫的光℡ 2024-11-25 01:44:38

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

Specify in url jsonso parameter.
Example:
var geocodeRequest = "http://dev.virtualearth.net/REST/v1/Locations/" + document.getElementById('txtQuery').value + "?jsonso=paramValue&output=json&jsonp=GeocodeCallback&key=" + credentials;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文