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からのものです。

alert(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 に答える