簡體   English   中英

解析和讀取來自Bing Maps REST服務的響應

[英]Parse and read response from Bing Maps REST service

使用Bing Maps Rest Service查找地址的經度/緯度。 我得到的響應還不錯,但是我在使用正確的語法來引用long / lat字段時遇到了麻煩(請參見調試器的屏幕截圖)。 我試過了

latitude = x.ResourceSets[0].Resources[0].GeocodePoints[0].Coordinates[0];

longitude = x.ResourceSets[0].Resources[0].GeocodePoints[0].Coordinates[1];

但它們不會編譯。

這是其余的服務電話...(不在屏幕截圖中)。

      private void GetResponse(Uri uri, Action<Response> callback)
  {
     System.Net.WebClient wc = new WebClient();
     wc.OpenReadCompleted += (o, a) =>
     {
        if (callback != null)
        {
           DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response));
           callback(ser.ReadObject(a.Result) as Response);
        }
     };
     wc.OpenReadAsync(uri);
  }

Studio調試屏幕截圖

根據您的屏幕快照,它看起來像x.ResourceSets[0].Resources[0]的類型為Location ,而該數組的基類為Resource 在訪問值之前,請嘗試投射它:

var location = (Location)x.ResourceSets[0].Resources[0];
latitude = location.GeocodePoints[0].Coordinates[0];
longitude = location.GeocodePoints[0].Coordinates[1];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM