Bing Map Silverlight使用基本密钥的结果不一致

时间:2014-02-20 07:58:09

标签: silverlight dynamics-crm-2011 bing-api bing-maps

您好我使用了以下代码,但有时我没有获得图钉,我使用的是Basic键,任何人都可以建议我。

    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 个答案:

答案 0 :(得分:1)

您应该提前对所有数据进行地理编码并存储坐标。试图像这样在运行中对一堆地址进行地理编码会增加应用程序生成的事务数量。当使用基本密钥时,如果在短时间内发出大量请求,则可以对速率进行限制。当请求是速率限制时,将标志添加到响应的标头以指示这一点。这在本页的下半部分记录:http://msdn.microsoft.com/en-us/library/ff701703.aspx