IEnumerator checkTerm(string addressSearch) { //string thisUrl="https://maps.googleapis.com/maps/api/geocode/json?address="+UnityWebRequest.EscapeURL(addressSearch)+"&key="+apiKey; Debug.Log(UnityWebRequest.EscapeURL(addressSearch)); string thisUrl = "https://www.geocode.farm/v3/json/forward/?addr=" + addressSearch + "&country=sv&lang=en&count=1"; string retJson; using (UnityWebRequest webRequest = UnityWebRequest.Post(thisUrl, UnityWebRequest.kHttpVerbGET)) { yield return(webRequest.SendWebRequest()); retJson = webRequest.downloadHandler.text; } JSONNode data = JSON.Parse(retJson); Debug.Log(data); string status = data["geocoding_results"]["STATUS"]["status"]; Debug.Log(status); if (status == "SUCCESS") { string div = " | "; string format = data["geocoding_results"]["RESULTS"][0]["ADDRESS"]["street_name"] + " " + data["geocoding_results"]["RESULTS"][0]["ADDRESS"]["street_number"] + div + data["geocoding_results"]["RESULTS"][0]["ADDRESS"]["postal_code"] + div + data["geocoding_results"]["RESULTS"][0]["ADDRESS"]["locality"] + div + data["geocoding_results"]["RESULTS"][0]["ADDRESS"]["admin_1"] + div + data["geocoding_results"]["RESULTS"][0]["ADDRESS"]["country"]; float latitude = float.Parse(data["geocoding_results"]["RESULTS"][0]["COORDINATES"]["latitude"]); float longitude = float.Parse(data["geocoding_results"]["RESULTS"][0]["COORDINATES"]["longitude"]); string name = format; Vector2 coordinate = new Vector2(latitude, longitude); GLOBAL.addresses.Add(new GLOBAL.Address(coordinate, name)); InstantiateAddresses instantiateAddresses = eventSystem.GetComponent(typeof(InstantiateAddresses)) as InstantiateAddresses; instantiateAddresses.updateAddresses(); } }
IEnumerator GetWorkRet(string apiKey) { bool finished = false; string retJson = ""; JSONNode retData = JSON.Parse(retJson); while (!finished) { using (UnityWebRequest webRequest = UnityWebRequest.Get("https://graphhopper.com/api/1/vrp/solution/" + job_id + "?key=" + apiKey)) { yield return(webRequest.SendWebRequest()); retJson = webRequest.downloadHandler.text; } retData = JSON.Parse(retJson); Debug.Log(retData["status"]); if (retData["status"] == "finished") { finished = true; } yield return(new WaitForSeconds(0.5f)); } Debug.Log(retJson); List <GLOBAL.Address> newAddresses = new List <GLOBAL.Address>(); for (int i = 1; i < GLOBAL.addresses.Count + 1; i++) { newAddresses.Add(GLOBAL.addresses[int.Parse(retData["solution"]["routes"][0]["activities"][i]["location_id"])]); } GLOBAL.addresses = newAddresses; InstantiateAddresses instantiateAddresses = eventSystem.GetComponent(typeof(InstantiateAddresses)) as InstantiateAddresses; instantiateAddresses.updateAddresses(); }
public void onFieldChange() { InputField inputField = textField.GetComponent(typeof(InputField)) as InputField; string searchTerm = inputField.text; InstantiateAddresses instantiateAddresses = eventSystem.GetComponent(typeof(InstantiateAddresses)) as InstantiateAddresses; CultureInfo culture = new CultureInfo("sv-SE", false); for (int i = 0; i < GLOBAL.addresses.Count; i++) { if (!(culture.CompareInfo.IndexOf(GLOBAL.addresses[i].name, searchTerm, CompareOptions.IgnoreCase) >= 0)) { GLOBAL.addresses[i].isVisible = false; } } instantiateAddresses.updateAddresses(); }
public void onDelete() { deleted = new List <int>(); List <GLOBAL.Address> newAddresses = new List <GLOBAL.Address>(); GameObject[] gameObjects = GameObject.FindGameObjectsWithTag(addressPrefab.tag); for (int i = 0; i < gameObjects.Length; i++) { ManageAddress manageAddress = gameObjects[i].GetComponent(typeof(ManageAddress)) as ManageAddress; if (!manageAddress.getCheck()) { newAddresses.Add(GLOBAL.addresses[i]); } } GLOBAL.addresses = newAddresses; InstantiateAddresses instantiateAddresses = eventSystem.GetComponent(typeof(InstantiateAddresses)) as InstantiateAddresses; instantiateAddresses.updateAddresses(); }