2011-06-30 2 views
0

は、私はこのように、コールバック機能付きビングジオコードリクエストを作成する方法を知っている:Bingマップ、7バージョンでコールバックなしでジオコード要求を行う方法?

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 
     } 

そのような要求をする機会だったのBing地図6.2バージョンで

(MSDN地図AJAXコントロール7.0 ISDKからコピー)次のコードを使用して:すべての変数が定義され、使用する準備ができていたので

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

をそれは非常に便利だったが、新バージョンではすべての私の変数が定義されていないと私はグローバルとしてそれらを行う必要はありませんので、あなたは知っていますどれか ソリューションそのようなコールバックなしでリクエストを行う方法?

答えて

0

URLで指定します。jsonsoパラメータ。 例:? VAR geocodeRequest = "http://dev.virtualearth.net/REST/v1/Locations/" +のdocument.getElementById( 'txtQuery')の値+」jsonso = paramValue &出力= & JSON JSONP = GeocodeCallback & key = "+ credentials;

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 }); 
} 
関連する問題