Google マップの API の結果から個々の住所コンポーネントを取得するのに問題があります。
この URL から受け取った結果は次のとおりです。
http://maps.googleapis.com/maps/api/geocode/json?address=jobing.com+glendale+arizona&sensor=false
この URL は「uri」変数にあります。これは、タイプごとに address_component を取得しようとするために使用しているコードです。私はC#で少し新しいことを考慮してください。
String Output = client.DownloadString(uri);
Dictionary<String, Object> RinkData = JsonConvert.DeserializeObject<Dictionary<String, Object>>(Output);
Dictionary<String, Object> RinkDataResults = (Dictionary<String, Object>) RinkData["results"];
if (RinkDataResults.ContainsKey("formatted_address"))
{
Route = GetAddressComponentByType(RinkDataResults["address_components"], "route");
}
そして、これが私が使用している関数「GetAddressComponentByType」です
protected String GetAddressComponentByType(Object AddressComponents, String AddressType)
{
Boolean MatchFound = false;
String MatchingLongName = "";
Dictionary<String, Object> AddressComponentsDict = (Dictionary<String, Object>)AddressComponents;
foreach (KeyValuePair<String, Object> ac in AddressComponentsDict)
{
Dictionary<String, Object> acDict = (Dictionary<String, Object>) ac.Value;
ArrayList acTypes = (ArrayList) acDict["types"];
foreach (String acType in acTypes)
{
if (acType == AddressType)
{
MatchFound = true;
break;
}
}
if (MatchFound)
{
MatchingLongName = (String) acDict["long_name"];
}
}
return MatchingLongName;
}
問題は、私のコンポーネント検索機能にさえ到達しないことです。RinkData["result"] を Dictionary に変換することは、無効な変換であると言って爆撃します。
誰かが私が間違っていることを見ていますか? または、誰かがGoogleマップのジオコード結果を読み取って機能するカスタムオブジェクトを持っているのでしょうか?