特定の場所から位置情報を取得したいので、Bing Map REST API を使用します。Url はうまく機能しますが、JSON コードを初めて使用するため、必要な出力を取得する方法がよくわかりません。
私は次のことを試しました:
string URL = "http://dev.virtualearth.net/REST/v1/Locations?countryRegion=&adminDistrict=&locality=Wien&postalCode=&addressLine=&userLocation=&userIp=&usermapView=&includeNeighborhood=&maxResults=&key=MY_KEY";
WebClient client = new WebClient();
client.OpenReadAsync(new Uri(URL, UriKind.Absolute));
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
private void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Point));
Point data = serializer.ReadObject(e.Result) as Point;
}
[DataContract]
public class Point
{
/// <summary>
/// Latitude,Longitude
/// </summary>
[DataMember(Name = "coordinates")]
public double[] Coordinates { get; set; }
}
ブラウザにリンクを入力すると、これが私の応答です。
{"authenticationResultCode":"ValidCredentials","brandLogoUri":"http://dev.virtualearth.net/Branding/logo_powered_by.png","copyright":"Copyright © 2013 Microsoft およびそのサプライヤー。無断複写・転載を禁じます。 Microsoft Corporation からの書面による明示的な許可がない限り、API にアクセスすることはできません。また、コンテンツおよび結果を使用、複製、または送信することはできません。","resourceSets":[{"estimatedTotal":1,"resources":[{" __type":"場所:http://schemas.microsoft.com/search/local/ws/rest/v1","bbox":[47.253395080566406,-123.16571807861328,47.946159362792969,-121.50344085693359],"名前":"シアトル、 WA","点":{"種類":"点","座標":[47.603561401367188,-122.32943725585938]},"address":{"adminDistrict":"WA","adminDistrict2":"King Co.","countryRegion":"United States","formattedAddress":"Seattle, WA","locality": "Seattle"},"confidence":"High","entityType":"PopulatedPlace","geocodePoints":[{"type":"Point","coordinates":[47.603561401367188,-122.32943725585938],"calculationMethod": "Rooftop","usageTypes":["Display"]}],"matchCodes":["Good"]}]}],"statusCode":200,"statusDescription":"OK","traceId":"08bee37ecb714d7cb7e2783eb8f873a4 |LTSM000177|02.00.183.2300|LTSIPEVM000039"}adminDistrict":"WA","adminDistrict2":"King Co.","countryRegion":"United States","formattedAddress":"Seattle, WA","locality":"Seattle"},"confidence":" High","entityType":"PopulatedPlace","geocodePoints":[{"type":"Point","coordinates":[47.603561401367188,-122.32943725585938],"calculationMethod":"屋上","usageTypes":[" Display"]}],"matchCodes":["Good"]}]}],"statusCode":200,"statusDescription":"OK","traceId":"08bee37ecb714d7cb7e2783eb8f873a4|LTSM000177|02.00.183.2300|LTSIPEVM000039"}adminDistrict":"WA","adminDistrict2":"King Co.","countryRegion":"United States","formattedAddress":"Seattle, WA","locality":"Seattle"},"confidence":" High","entityType":"PopulatedPlace","geocodePoints":[{"type":"Point","coordinates":[47.603561401367188,-122.32943725585938],"calculationMethod":"Rooftop","usageTypes":[" Display"]}],"matchCodes":["Good"]}]}],"statusCode":200,"statusDescription":"OK","traceId":"08bee37ecb714d7cb7e2783eb8f873a4|LTSM000177|02.00.183.2300|LTSIPEVM000039"}countryRegion":"United States","formattedAddress":"Seattle, WA","locality":"Seattle"},"confidence":"High","entityType":"PopulatedPlace","geocodePoints":[{" type":"Point","coordinates":[47.603561401367188,-122.32943725585938],"calculationMethod":"Rooftop","usageTypes":["Display"]}],"matchCodes":["Good"]}]} ],"statusCode":200,"statusDescription":"OK","traceId":"08bee37ecb714d7cb7e2783eb8f873a4|LTSM000177|02.00.183.2300|LTSIPEVM000039"}countryRegion":"United States","formattedAddress":"Seattle, WA","locality":"Seattle"},"confidence":"High","entityType":"PopulatedPlace","geocodePoints":[{" type":"Point","coordinates":[47.603561401367188,-122.32943725585938],"calculationMethod":"Rooftop","usageTypes":["Display"]}],"matchCodes":["Good"]}]} ],"statusCode":200,"statusDescription":"OK","traceId":"08bee37ecb714d7cb7e2783eb8f873a4|LTSM000177|02.00.183.2300|LTSIPEVM000039"}entityType":"PopulatedPlace","geocodePoints":[{"type":"Point","coordinates":[47.603561401367188,-122.32943725585938],"calculationMethod":"Rooftop","usageTypes":["Display"]} ],"matchCodes":["良い"]}]}],"statusCode":200,"statusDescription":"OK","traceId":"08bee37ecb714d7cb7e2783eb8f873a4|LTSM000177|02.00.183.2300|LTSIPEVM000039"}entityType":"PopulatedPlace","geocodePoints":[{"type":"Point","coordinates":[47.603561401367188,-122.32943725585938],"calculationMethod":"Rooftop","usageTypes":["Display"]} ],"matchCodes":["良い"]}]}],"statusCode":200,"statusDescription":"OK","traceId":"08bee37ecb714d7cb7e2783eb8f873a4|LTSM000177|02.00.183.2300|LTSIPEVM000039"}statusDescription":"OK","traceId":"08bee37ecb714d7cb7e2783eb8f873a4|LTSM000177|02.00.183.2300|LTSIPEVM000039"}statusDescription":"OK","traceId":"08bee37ecb714d7cb7e2783eb8f873a4|LTSM000177|02.00.183.2300|LTSIPEVM000039"}
私の質問は次のとおりです。これは正しい方法ですか?また、データを取得するにはどうすればよいですか?
あなたが私を助けてくれることを願っています.私はすでにこの問題に多くの時間を費やしました.
- - -編集 - - -
今は JSON.net を使用していますが、Web サイトから取得したデータを文字列変数に解析する方法がわかりません。
私は次のことを試しました:
var json = new WebClient().DownloadString("url");
しかし、私はWindows Phoneで開発しているため、これは機能しません。
System.Net.WebClient には「DownloadString」の定義が含まれていません...
誰でも、Windows Phone アプリでこれを機能させるのを手伝ってくれます。