Guide to Choosing TrackAsia's Search and Autocomplete API Services
TrackAsia provides high-quality digital mapping API services, specifically designed for the Vietnamese market, with the goal of optimizing costs, easy integration, and accurate data. Among TrackAsia's services, API Search and API Autocomplete are two powerful tools that support location and address search. This article will guide you in choosing between these two APIs, explaining the differences and appropriate use cases to help you make the right decision.
Overview of TrackAsia's Search and Autocomplete APIs
API Search
API Search allows searching for addresses, locations, or geographic information based on keywords or specific conditions.
Key Features
- Have complete address and need accurate coordinates
- Search for specific locations
- Need final results instead of suggestions
Usage Example
// Search for complete address
const params = new URLSearchParams({
query: 'Landmark 81, 720A Điện Biên Phủ, Phường Thạnh Mỹ Tây, Thành phố Hồ Chí Minh',
key: 'public_key'
});
fetch(`https://maps.track-asia.com/api/v2/place/textsearch/json?${params}`)
.then(res => res.json())
.then(data => {
const location = data?.results?.[0]?.geometry?.location;
console.log('Coordinates:', location);
})
.catch(err => {
console.error('Query error:', err);
});
Results
Keyword: "Landmark 81, 720A Điện Biên Phủ, Phường Thạnh Mỹ Tây, Thành phố Hồ Chí Minh"
Result: Returns geographic coordinates corresponding to the searched location
- "{ lat: 10.795845, lng: 106.716234 }"
The result information includes accurate coordinates (latitude, longitude) used to display the location on a map or process subsequent positioning requests. The result is typically a single object that best matches the natural language query.
API Autocomplete
API Autocomplete is designed to suggest quick searches for addresses or locations based on a partial keyword that users input. The goal is to support faster and more accurate data entry processes, based on standardized geographic data in the system.
Key Features
- Instant suggestions: Returns a list of suitable locations or addresses as soon as users type a few characters.
- Optimized user experience: Helps users quickly select the correct location without needing to type the complete keyword.
- Only have short keywords or unclear terms
Usage Example
const params = new URLSearchParams({
input: 'Landmark 81',
bounds: '21.6463420,104.8429379;21.7503187,104.9330227',
size: '2',
new_admin: 'true',
key: 'public_key'
});
const autocompleteUrl = 'https://maps.track-asia.com/api/v2/place/autocomplete/json?' + params;
fetch(autocompleteUrl)
.then(res => res.json())
.then(data => {
console.log('Suggestions:', data.predictions);
})
.catch(err => {
console.error('API error:', err);
});
Results
Keyword: "Landmark 81"
Result: Returns a list of suggested suitable locations
-
"KIMMAY Landmark 81, 772 Đường Điện Biên Phủ, Phường Vườn Lài, Thành phố Hồ Chí Minh"
-
"MK Restaurant Landmark 81, Phường Thạnh Mỹ Tây, Thành phố Hồ Chí Minh"
The results include location descriptions, usually with ward/commune, province/city information. The suggestion data primarily serves the purpose of supporting fast data entry.
Detailed Comparison
Criteria | API Search | API Autocomplete |
---|---|---|
Main Purpose | Search for detailed locations/addresses based on keywords or specific conditions. | Quick suggestions for locations/addresses when users input partial keywords. |
Input | Complete address | Short keywords |
Return Results | Detailed information about locations (coordinates, complete address, location type). | List of suggested locations/addresses for users to choose from. |
Accuracy | High, focused on accurate and complete results. | High, focused on quick suggestions, supporting input errors. |
Use Cases | Accurate search, integration into analysis systems or data management. | Search suggestions in user interfaces, mobile apps or websites. |
Input Error Handling | Yes, but focused on final results. | More optimized, suggests even with typos or abbreviations. |
Real-world Usage Flow
Scenario 1: Finding Specific Address
// Step 1: Suggest keywords with Autocomplete
const suggestions = await fetch('https://maps.track-asia.com/api/v2/place/autocomplete/json?input=Landmark 81&bounds=21.6463420,104.8429379;21.7503187,104.9330227&size=2&key=public_key')
.then(r => r.json());
// Display suggestions
console.log('Location suggestions:', suggestions.predictions);
// Step 2: User selects location -> get coordinates via TextSearch
const selectedPlace = 'Landmark 81, 720A Điện Biên Phủ, Phường Thạnh Mỹ Tây, Thành phố Hồ Chí Minh';
const coordinates = await fetch(`https://maps.track-asia.com/api/v2/place/textsearch/json?query=${encodeURIComponent(selectedPlace)}&key=public_key`)
.then(r => r.json());
// Get coordinates
const placeLocation = coordinates.results[0].geometry.location;
console.log('Coordinates:', placeLocation);
Scenario 2: Direct Search
// Use Search immediately when you have complete address
const fullAddress = 'Landmark 81, 720A Điện Biên Phủ, Phường Thạnh Mỹ Tây, Thành phố Hồ Chí Minh';
const result = await fetch(`https://maps.track-asia.com/api/v2/place/textsearch/json?query=${encodeURIComponent(fullAddress)}&key=public_key`)
.then(r => r.json());
const coordinates = result.results[0].geometry.location;
console.log('Coordinates:', coordinates);