ThinkGeo Cloud REST API
With professional base maps, geocoding, routing and much more, the ThinkGeo Cloud is the perfect solution to take your app to the next level.
A while back, we had a blog post with examples of accessing our Cloud from its Javascript API. In today’s post, we will show an example using the Cloud’s REST API.
REST APIs use HTTP methods like GET, POST, PUT, and DELETE to fetch and manipulate resources. RESTful APIs are ubiquitous and supported by all programming languages. Whether you’re working in C#, Python, Java, PHP, Swift or Go, accessing the ThinkGeo cloud’s REST Apis are a breeze.
The quickest way to see the the REST API in action is to check out our API test suite here.
A Reverse Geocoding Example
While the ThinkGeoCloud has many different services, we’ve chosen Reverse Geocoding for today’s example. This is the process of converting a location (in this case a latitude/longitude value) into a human-readable address or place name.
Step 1 - Authorize
Near the top of the API test suite page, you’ll see an ‘Authorize’ button. You’ll need to click this button and enter your Client Credentials or Javascript API key and click the ‘Authorize’ button again. After you’re authorized, your credentials will be sent with all your ensuing REST requests.
To find your Client Credentials, you can log into the cloud here and click on ‘Clients’. If you’re new to ThinkGeo, you can sign up here and create your ThinkGeo account.
Step 2 - Execute the Reverse Geocode Function
Once you are authorized, click on the first ‘GET’ function under the ReverseGeocoding section. This request has a signature of: /api/v1/location/reverse-geocode/{pointY},{pointX} and we’ll be entering an x and y value for the latitude and longitude. In this example, we’ll be entering 32.7755 for the pointY value and -96.8087 for the pointX value.
Once you’ve entered the appropriate x and y values, just click the ‘Execute’ button and you’ll see a result like the one on the right. In this case, the lat/lon returns the address for the Hyatt Regency in Dallas as well as many other details about the location.
Code Samples
Once you’ve explored a new service in the API test suite, you’ll eventually need to access the service from your project’s codebase. Below are a few examples of accessing the Reverse Geocoding service in C#, Python, Java and PHP.
C#
// The URL of the Cloud API Reverse Geocode Endpoint
string url = "https://cloud.thinkgeo.com/api/v1/location/reverse-geocode/32.7755,-96.8087?APIKey=insert_api_key_here";
// Send a GET request to the specified Uri
HttpResponseMessage response = await client.GetAsync(url);
// Read the response content as a string
string responseBody = await response.Content.ReadAsStringAsync();
// Output the response content to the console
Console.WriteLine(responseBody);
Python
# The URL of the Cloud API Reverse Geocode Endpoint
url = "https://cloud.thinkgeo.com/api/v1/location/reverse-geocode/32.7755,-96.8087?APIKey=insert_api_key_here"
# Send a GET request to the specified URL
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
# Output the response content to the console
print(response.text)
Java
// The URL of the Cloud API Reverse Geocode Endpoint
String url = "https://cloud.thinkgeo.com/api/v1/location/reverse-geocode/32.7755,-96.8087?APIKey=insert_api_key_here";
// Create a URL object
URL obj = new URL(url);
// Open a connection
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// Set the request method to GET
con.setRequestMethod("GET");
// Reading the response
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// Output the response content to the console
System.out.println(response.toString());
PHP
// The URL of the Cloud API Reverse Geocode Endpoint
$url = "https://cloud.thinkgeo.com/api/v1/location/reverse-geocode/32.7755,-96.8087?APIKey=insert_api_key_here";
// Initialize a cURL session
$ch = curl_init($url);
// Set options for the cURL session
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
// Execute the cURL session and get the response content as a string
$responseBody = curl_exec($ch);
// Close the cURL session
curl_close($ch);
// Output the response content to the console
echo $responseBody;
More Information
We hope you’ve found this article useful. Check out docs.thinkgeo.com for more details and pricing. We encourage your to start your free cloud evaluation today and get your API keys to start building!
If you have any questions on ThinkGeo Cloud, please contact sales@thinkgeo.com - we look forward to hearing from you.