public static IEnumerator suggestionToGeocode(SuggestAddresses suggestaddress, Action <SuggestionLocation[]> callback) { string url = string.Format("{0}/findAddressCandidates?magicKey={1}&f=json", new object[] { URL, suggestaddress.magicKey, }); UnityWebRequest www = UnityWebRequest.Get(url); yield return(www.SendWebRequest()); // Extract token from parsed response var text = www.downloadHandler.text.Replace(":null", ":\"\""); var json = JSON.Parse(text); if (json.ContainsKey("error")) { callback(null); yield break; } var candidates = json["candidates"]; SuggestionLocation[] suggestLocations = new SuggestionLocation[candidates.Count]; for (int i = 0; i < candidates.Count; i++) { suggestLocations[i] = new SuggestionLocation(); suggestLocations[i].Location = new Coordinate(); suggestLocations[i].address = candidates[i]["address"].Value; float f = float.Parse(candidates[i]["location"]["x"].Value, CultureInfo.InvariantCulture.NumberFormat); suggestLocations[i].Location.Longitude = float.Parse(candidates[i]["location"]["x"].Value, CultureInfo.InvariantCulture.NumberFormat); suggestLocations[i].Location.Latitude = float.Parse(candidates[i]["location"]["y"].Value, CultureInfo.InvariantCulture.NumberFormat); suggestLocations[i].score = candidates[i]["score"].Value; } callback(suggestLocations); }
public static IEnumerator GetSuggestGeocode(string keyword, Coordinate coordinate, Action <SuggestAddresses[]> callback) { string url = string.Format("{0}/suggest?text={1}&location={2},{3}&f=json", new object[] { URL, keyword, coordinate.Longitude, coordinate.Latitude, max_suggestion, }); UnityWebRequest www = UnityWebRequest.Get(url); yield return(www.SendWebRequest()); // Extract token from parsed response var text = www.downloadHandler.text.Replace(":null", ":\"\""); var json = JSON.Parse(text); if (json.ContainsKey("error")) { callback(null); yield break; } var suggestions = json["suggestions"]; SuggestAddresses[] suggestAddresses = new SuggestAddresses[suggestions.Count]; for (int i = 0; i < suggestions.Count; i++) { if (suggestions[i]["isCollection"].Value.Equals("true")) { suggestAddresses[i] = new SuggestAddresses(); suggestAddresses[i].address = suggestions[i]["text"].Value; suggestAddresses[i].magicKey = suggestions[i]["magicKey"].Value; } } callback(suggestAddresses); }