2010-02-22 58 views
2

我正在做一些關於如何使用Bing Maps進行建議的應用程序的研究,並且我遇到了一堵牆。總的想法是我想要顯示距離某個位置X距離內的各種物品的位置。起點是美國地圖,我們使用用戶的點擊來獲取緯度/經度,並用它來選擇最近的城市。我們會將地圖居中,然後在規定距離內爲我們的每件物品加載圖釘。Bing地圖的VEMap.Find爲什麼會失敗?

在構建演示的過程中,我寫了以下內容。我遇到的問題是,在plotZipcode中調用landMap.Find失敗。沒有錯誤消息和控制檯在landMap.Find顯示之前和之後輸出,但是plotPushpin從不執行。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 
<script charset="UTF-8" type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&mkt=en-us"></script> 
<script type="text/javascript"> 
    var landMap = null; 

    function getLatLong(evt) { 
     var latLong = landMap.PixelToLatLong(new VEPixel(evt.mapX, evt.mapY)); 
     // This looks up the nearest city from the lat/long 
     // and returns something like "EAGLE CREEK, IN" 
     $.ajax({ 
      url: '/cfc/bing.cfc', 
      data: { 
       method: 'findCity', 
       Latitude: latLong.Latitude, 
       Longitude: latLong.Longitude 
      }, 
      success: plotZipcode 
     }); 
    } 

    function plotPushpin(layer, results, places, expectMore, errorMessage) { 
     console.log('Executing plotPushpin...'); 
     if (landMap && places && places.length >= 1) { 
      var pushpin = new VEShape(VEShapeType.Pushpin, places[0].LatLong); 
      pushpin.SetTitle('Available Repos Near '+places[0].Name); 
      landMap.AddShape(pushpin); 
     } 
    } 

    function plotZipcode(data, textStatus, XMLHttpRequest) { 
     console.log('Executing plotZipcode...'); 
     if (landMap && data.length > 0) { 
      console.log(data); 
      landMap.Clear(); 
      console.log('Calling VEMap.Find...'); 
      landMap.Find(null, data, null, null, null, null, null, null, null, null, plotPushpin); 
      //landMap.Find(null, data); // This doesn't work either.' 
      console.log('Called VEMap.Find!'); 
     } 
    } 

    $(document).ready(function() { 
     landMap = new VEMap('landLocation'); 
     landMap.LoadMap(); 
     landMap.ShowDisambiguationDialog(false); 
     landMap.AttachEvent('onclick', getLatLong); 
    }); 
</script> 
<div id='landLocation' style="position:absolute; width:600px; height:400px;"></div> 

的特別令人沮喪的是,如果我使用Firebug手動執行以下,它的行爲完全按照預期:

landMap.Find(null, "EAGLE CREEK, IN", null, null, null, null, null, null, null, null, plotPushpin); 

任何瞭解爲什麼VEMap.Find僅僅是從內無所事事我AJAX回調將不勝感激。

+0

您是否使用VEMap.SetCredentials()方法指定了憑據? - http://msdn.microsoft.com/en-us/library/ee692182.aspx – 2013-01-30 06:48:54

回答

0

這個問題是一個Firefox的問題。出於某種原因,JQuery doc ready函數不喜歡用加載映射的函數的引用來運行。如果您將mapload方法放在body onload事件(html或純javascript - 而不是jquery)中,它將起作用。

相關問題