2014-02-20 17 views
0

嗨我已經使用下面的代碼,但有時我沒有得到圖釘,我使用的基本鍵可以任何一個請建議我。Bing Map Silverlight使用基本鍵的結果不一致

public MainPage() 
    { 
     InitializeComponent(); 
     Geocode("8800 Lyra Avenue, Columbus, OH 43240", 1); 
     Geocode("2137 Birchwood Dr, Redmond,WA 78214,U.S.", 1); 
     Geocode("Santa Cruz, Duval Co., TX", 1); 
    } 
    private void Geocode(string address, int waypointIndex) 
    { 
     PlatformServices.GeocodeServiceClient geocodingService = new PlatformServices.GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); 
     geocodingService.GeocodeCompleted += new EventHandler<TestSL.PlatformServices.GeocodeCompletedEventArgs>(geocodingService_GeocodeCompleted); 

     PlatformServices.GeocodeRequest request = new PlatformServices.GeocodeRequest(); 
     request.Credentials = new TestSL.PlatformServices.Credentials(); 
     request.Credentials.ApplicationId = ((Microsoft.Maps.MapControl.ClientTokenCredentialsProvider)(MyMap.CredentialsProvider)).Token; 
     request.Query = address; 

     geocodingService.GeocodeAsync(request, waypointIndex); 
    } 
    public void geocodingService_GeocodeCompleted(object sender, TestSL.PlatformServices.GeocodeCompletedEventArgs e) 
    { 
     MapLayer myMapLayer = new MapLayer(); 
     MyMap.Children.Add(myMapLayer); 
     // create a location collection class 
     LocationCollection myLocationColl = new LocationCollection(); 
     var geoResult = (from r in e.Result.Results 
         orderby (int)r.Confidence ascending 
         select r).FirstOrDefault(); 
     if (geoResult != null) 
     { 

      Pushpin myPushPin = new Pushpin(); 
      // set it to first found location 
      myPushPin.Location = new Microsoft.Maps.MapControl.Location(geoResult.Locations[0].Latitude, geoResult.Locations[0].Longitude); 
      ToolTipService.SetToolTip(myPushPin, geoResult.DisplayName); 
      // add it to location collection 
      // which would be used to set the map's bound 
      myLocationColl.Add(myPushPin.Location); 
      // Add the drawn point to the route layer.     
      myMapLayer.Children.Add(myPushPin); 
     } 
    } 

有時我得到兩個圖釘和有時我沒有得到任何東西,有時我得到1或3。任何一個可以告訴我爲什麼發生這種情況。

回答

1

您應該提前對所有數據進行地理編碼並存儲座標。試圖像這樣對一堆地址進行地理編碼會增加應用程序生成的事務數量。當使用基本密鑰時,如果在很短的時間內發出一堆請求,它可能會受到速率限制。當請求被速率限制時,標誌被添加到響應的頭部以指示這一點。這在此頁面的下半部分有記錄:http://msdn.microsoft.com/en-us/library/ff701703.aspx