Getting started overview
Integrating Longdo Map into an application involves several steps: account creation, API key acquisition, and making an initial API call. Longdo Map provides mapping, geocoding, and routing services with a focus on geographical data within Thailand (Longdo Map API documentation). Developers can access these services via RESTful APIs and a JavaScript SDK (Longdo Map SDKs). This guide outlines the process for making a first request, specifically targeting the Longdo Geocoding API.
Before proceeding, ensure you have a basic understanding of web requests (HTTP/HTTPS) and, if using the JavaScript SDK, familiarity with JavaScript development. The Longdo Map platform includes a free tier, allowing up to 50,000 API calls per month for evaluation and development purposes (Longdo Map pricing details).
Here is a quick reference table for the getting started process:
| Step | What to do | Where |
|---|---|---|
| 1. Sign Up | Register for a Longdo Map account. | Longdo Map Sign Up page |
| 2. Get API Key | Generate or locate your API key in the developer console. | Longdo Map Developer Console |
| 3. Choose API | Select the specific Longdo Map API (e.g., Geocoding). | Longdo Map API reference |
| 4. Construct Request | Formulate your API request with the key and parameters. | Longdo Geocoding API documentation |
| 5. Send Request | Execute the API call using a tool or code. | Command line (cURL), browser, programming language |
| 6. Process Response | Handle the JSON data returned by the API. | Your application code |
Create an account and get keys
To access Longdo Map's APIs, you must first create a developer account. This account provides access to the developer console where API keys are managed. Follow these steps:
- Navigate to the Longdo Map website: Go to the official Longdo Map homepage.
- Sign Up: Look for a 'Sign Up' or 'Register' link. The registration process typically requires an email address, password, and agreement to terms of service (Longdo Map sign-up instructions).
- Verify Email: After registration, you may receive an email verification link. Click this link to activate your account.
- Log In: Once your account is active, log in to the Longdo Map developer console.
- Generate API Key: Within the developer console, locate the section for API keys or credentials. You will typically find an option to generate a new API key. This key is a unique string of characters that authenticates your requests to the Longdo Map APIs. Copy this key and store it securely, as it is required for all API calls (Longdo Map API key generation guide).
The API key acts as a credential, similar to how Google Maps Platform API keys function, identifying your application and authorizing its usage against your account's quota.
Your first request
This section demonstrates how to make a basic request to the Longdo Geocoding API using your newly acquired API key. We will use a simple HTTP GET request to convert a Thai address into geographical coordinates (latitude and longitude).
Geocoding an Address with cURL
The Longdo Geocoding API allows you to convert human-readable addresses into geographic coordinates. The base URL for the Geocoding API is https://api.longdo.com/map/api/geocode/ (Longdo Geocoding API reference). A common parameter is search for the address string and key for your API key.
Example Request (cURL):
Replace YOUR_API_KEY with the actual API key you obtained from the developer console.
curl -X GET "https://api.longdo.com/map/api/geocode/?search=%E0%B8%AA%E0%B8%96%E0%B8%B2%E0%B8%99%E0%B8%B5%E0%B8%A3%E0%B8%96%E0%B9%84%E0%B8%9F%E0%B8%9F%E0%B9%89%E0%B8%B2%E0%B8%81%E0%B8%A3%E0%B8%B8%E0%B8%87%E0%B9%80%E0%B8%97%E0%B8%9E&key=YOUR_API_KEY"
In this example, %E0%B8%AA%E0%B8%96%E0%B8%B2%E0%B8%99%E0%B8%B5%E0%B8%A3%E0%B8%96%E0%B9%84%E0%B8%9F%E0%B8%9F%E0%B9%89%E0%B8%B2%E0%B8%81%E0%B8%A3%E0%B8%B8%E0%B8%87%E0%B9%80%E0%B8%97%E0%B8%9E is the URL-encoded Thai phrase for "Bangkok Skytrain Station" (สถานีรถไฟฟ้ากรุงเทพฯ). URL encoding is crucial for non-ASCII characters in API requests, as specified by standards like RFC 3986 for URI Generic Syntax.
Expected JSON Response:
[
{
"lon": 100.56708,
"lat": 13.73881,
"address": "สถานีรถไฟฟ้ากรุงเทพฯ",
"road": "ถนนสุขุมวิท",
"district": "คลองเตย",
"province": "กรุงเทพมหานคร",
"id": "1011000010001"
}
]
The response is a JSON array containing one or more objects, each representing a geocoded result. Key fields include lon (longitude), lat (latitude), and address. The exact structure and fields may vary slightly depending on the specific query and API version (Longdo Geocoding API response format).
Using the JavaScript SDK
For web applications, the Longdo Map JavaScript SDK simplifies integration. You embed the SDK script in your HTML and then use its functions to initialize maps and interact with services.
HTML Structure:
<!DOCTYPE html>
<html>
<head>
<title>Longdo Map First Request</title>
<meta charset="utf-8">
<style>
html, body { height: 100%; margin: 0; padding: 0; }
#map { height: 100%; width: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript" src="https://map.longdo.com/mmmap/mmmap.php?key=YOUR_API_KEY"></script>
<script>
var map;
function init() {
map = new longdo.Map({
placeholder: document.getElementById('map'),
language: 'en'
});
// Example: Add a marker at a specific location
map.Event.addListener('ready', function() {
map.location(longdo.LocationMode.LatitudeLongitude, {
lon: 100.56708,
lat: 13.73881
});
map.zoom(15);
map.Ui.Crosshair.visible(false);
map.Ui.Geolocation.visible(false);
map.Ui.Scale.visible(false);
map.Ui.Zoombar.visible(false);
map.Ui.Toolbar.visible(false);
});
// Example: Geocode an address using the SDK
longdo.Geocoding.search("สถานีรถไฟฟ้ากรุงเทพฯ", function(result) {
if (result.items.length > 0) {
console.log("Geocoded address:", result.items[0].address);
console.log("Latitude:", result.items[0].lat);
console.log("Longitude:", result.items[0].lon);
// Optionally add a marker to the map
map.Overlays.add(new longdo.Marker({
lon: result.items[0].lon,
lat: result.items[0].lat
}));
}
});
}
</script>
</body>
</html>
Replace YOUR_API_KEY in the src attribute of the script tag with your actual API key. The init() function is automatically called once the SDK is loaded. This example initializes a map and then performs a geocoding search, logging the results to the browser console and placing a marker on the map (Longdo Map JavaScript SDK documentation).
Common next steps
After successfully making your first request, consider these common next steps to further integrate Longdo Map into your application:
- Explore other APIs: Longdo Map offers additional services such as the Longdo Routing API for calculating directions and the Longdo Search API for points of interest (Longdo Map API overview). Review the API reference to identify services relevant to your application's needs.
- Implement error handling: Production applications require robust error handling. The Longdo Map APIs return specific error codes and messages for invalid requests, rate limits, or server issues. Your application should be designed to gracefully handle these responses.
- Monitor usage: Keep track of your API call usage through the Longdo Map developer console to ensure you stay within your free tier limits or subscribed plan (Longdo Map pricing and usage monitoring).
- Secure your API key: Never expose your API key in client-side code for public-facing applications. For server-side applications, store it as an environment variable. For client-side SDK usage, ensure your key is restricted to specific domains or IP addresses if the platform supports such security features.
- Integrate advanced features: Beyond basic mapping and geocoding, explore features like custom map styles, adding multiple markers, displaying routes, and integrating real-time location data if applicable.
- Review terms of service: Understand the Longdo Map Terms of Service and usage policies, particularly regarding data caching and display requirements.
Troubleshooting the first call
Encountering issues during your initial API call is common. Here are some troubleshooting steps:
- Invalid API Key: Double-check that you have copied the API key correctly. An incorrect key will typically result in an authentication error (e.g., HTTP 401 Unauthorized). Ensure there are no leading or trailing spaces.
- Missing API Key: Verify that the
keyparameter is present in your URL or correctly passed to the SDK initialization. - Rate Limit Exceeded: If you make too many requests in a short period, especially during testing, you might hit rate limits, resulting in an HTTP 429 Too Many Requests error. Wait a few minutes before trying again or check your usage dashboard.
- Incorrect URL or Endpoint: Ensure the base URL and endpoint path are correct for the specific API you are calling (e.g.,
/geocode/for geocoding). Refer to the Longdo Map API reference for exact endpoints. - URL Encoding Issues: For parameters containing non-ASCII characters (like Thai addresses), ensure they are properly URL-encoded. Failure to do so can lead to malformed requests or incorrect results. Tools like online URL encoders can help verify this.
- Network Connectivity: Confirm that your environment has an active internet connection and no firewall rules are blocking outgoing requests to
api.longdo.com. - Browser Console Errors (for SDK): If using the JavaScript SDK, open your browser's developer console (F12) to check for JavaScript errors or network request failures.
- Documentation Language Barrier: The primary documentation for Longdo Map is in Thai (Longdo Map documentation). If you are a non-Thai speaker, use browser translation features or focus on the English sections and code examples provided.