But, if you click the link, I need the info "name":"Johnson County". I have a field called City_Limits where I would like the value "name" to be inputed into City_Limits field. Is this possible? I can't seem to figure it out and I asked Chatgpt but it's telling me to do JSON functions etc. Any help would be amazing.
I would do an openurl and put Lat & Long fields in replace of link above, but not sure how to pull that info back into my form I called it from. Thanks.
Chatgpt told me to do this and maybe you can help me figure this out or how to do this.
// Custom function to retrieve city name from Geoapify API
// Parameters: latitude, longitude
// Returns: city name
// Function to make HTTP GET request
function makeHttpGetRequest(url) {
// Set up the HTTP request
req = new HTTPRequest();
req.setURL(url);
req.setMethod("GET");
// Send the HTTP request and retrieve the response
res = req.send();
// Return the response
return res;
}
// Function to extract city name from JSON response
function extractCityName(response) {
// Find the starting and ending positions of the city name
startIndex = instr(response, "name\":\"") + 7;
endIndex = instr(startIndex, response, "\",");
// Extract the city name
cityName = response[startIndex:endIndex];
// Return the city name
return cityName;
}
// Custom function to retrieve city name based on latitude and longitude
function getCityName(latitude, longitude) {
// Construct the API URL with the latitude, longitude, and API key
apiUrl = "https://api.geoapify.com/v1/boundaries/part-of?lon=" + longitude + "&lat=" + latitude + "&apiKey=API KEY";
// Make the HTTP GET request
response = makeHttpGetRequest(apiUrl);
// Extract the city name from the response
cityName = extractCityName(response);
// Return the city name
return cityName;
}