Migrate from Longdo Map to MapScale
Move a Longdo Map JavaScript API integration, including search, reverse geocoding and routing web services, to MapScale endpoints and MapLibre GL JS for Thai developers.
Intermediate
What changes
Both services focus on Thailand. Longdo exposes its own longdo.Map object API and REST web services, while MapScale serves MapLibre-compatible styles and a REST API. Coordinates become [longitude, latitude] arrays instead of { lon, lat } objects. Publishable keys (pk_) are for browsers and apps and reach styles, tiles, autocomplete, place details and static maps. Secret keys (sk_) are server-only and are required for geocode, reverse, route, matrix and isochrone. The Longdo snippets below follow its v2 JavaScript documentation; confirm names against the version you use.
Longdo Map JavaScript API MapScale
new longdo.Map({ placeholder }) new maplibregl.Map({ container, style, center, zoom })
{ lon, lat } objects [lng, lat] arrays (GeoJSON order)
map.location(...), map.zoom(...) center / zoom options, map.flyTo(...)
longdo.Marker + Overlays.add maplibregl.Marker + maplibregl.Popup
search.longdo.com .../suggest GET /v1/autocomplete?q= (publishable key)
search.longdo.com .../search GET /v1/geocode?q= (secret key, server)
api.longdo.com/map/services/address GET /v1/reverse?point=lng,lat (secret key, server)
RouteService .../geojson/route GET /v1/route?coordinates=lng,lat;lng,lat&profile=driving
locale=th lang=thReplace the map
Replace longdo.Map with a MapLibre map that loads a MapScale style. Use lang=th or lang=en on the style URL for label language.
// Before: Longdo Map JavaScript API (v2 style, from the Longdo documentation)
// <script src="https://api.longdo.com/map/?key=YOUR_LONGDO_KEY"></script>
const map = new longdo.Map({ placeholder: document.getElementById("map") })
map.location({ lon: 100.5018, lat: 13.7563 }, true)
map.zoom(11, true)
// After: MapScale style rendered by MapLibre GL JS
const key = "pk_test_your_key_here"
const map = new maplibregl.Map({
container: "map",
style: `https://api.mapscale.io/styles/v1/streets?key=${key}&lang=th`,
center: [100.5018, 13.7563], // [lng, lat]
zoom: 11,
})Replace markers
A longdo.Marker with title and detail options becomes a MapLibre marker with a popup. Use setText for plain text.
// Before: Longdo Map JavaScript API
const marker = new longdo.Marker(
{ lon: 100.5018, lat: 13.7563 },
{ title: "Bangkok", detail: "Example marker" }
)
map.Overlays.add(marker)
// After: MapLibre GL JS
const popup = new maplibregl.Popup().setText("Bangkok: example marker")
new maplibregl.Marker().setLngLat([100.5018, 13.7563]).setPopup(popup).addTo(map)Replace place search
Longdo's suggest and search web services map to autocomplete (publishable key, browser-safe) and geocode (secret key, server only). Pass the place_id from a prediction to GET /v1/place/{id} to get coordinates.
// Before: Longdo web service (key in the query string)
// https://search.longdo.com/mapsearch/json/suggest?keyword=siam&limit=10&key=YOUR_LONGDO_KEY
// https://search.longdo.com/mapsearch/json/search?keyword=siam&locale=th&limit=20&key=YOUR_LONGDO_KEY
// After, suggestions in the browser (publishable key):
const params = new URLSearchParams({ q: "siam", lang: "th", key: "pk_test_your_key_here" })
const suggestResponse = await fetch(`https://api.mapscale.io/v1/autocomplete?${params}`)
if (!suggestResponse.ok) throw new Error(`MapScale autocomplete failed: ${suggestResponse.status}`)
const { predictions } = await suggestResponse.json()
// predictions[0].place_id -> GET /v1/place/{id} for latitude and longitude
// After, full geocoding on your server (secret key):
const serverParams = new URLSearchParams({ q: "siam", lang: "th", limit: "20" })
const geocodeResponse = await fetch(`https://api.mapscale.io/v1/geocode?${serverParams}`, {
headers: { "X-MapScale-Key": process.env.MAPSCALE_SECRET_KEY },
})
if (!geocodeResponse.ok) throw new Error(`MapScale geocode failed: ${geocodeResponse.status}`)
const collection = await geocodeResponse.json()Replace reverse geocoding
Reverse geocoding runs on your server with a secret key. Treat the numeric ids returned by the admin-areas endpoint as MapScale ids, not as PCODEs; if you join on Thai administrative codes, use the PCODE reference to look up the code for each area.
// Before: Longdo address web service
// https://api.longdo.com/map/services/address?lon=100.53726&lat=13.72427&key=YOUR_LONGDO_KEY
// After: your server, secret key
const params = new URLSearchParams({ point: "100.53726,13.72427", lang: "th" }) // lng,lat
const response = await fetch(`https://api.mapscale.io/v1/reverse?${params}`, {
headers: { "X-MapScale-Key": process.env.MAPSCALE_SECRET_KEY },
})
if (!response.ok) throw new Error(`MapScale reverse failed: ${response.status}`)
const collection = await response.json()
const place = collection.features[0].properties // formattedAddress, subdistrict, district, province, postalCode
// Administrative areas only:
// GET /v1/admin-areas/reverse?point=100.53726,13.72427&lang=th
// returns subdistrict, district, province and country as { id, name }.Replace routing
Longdo's flon, flat, tlon and tlat parameters become one coordinates list. The route API documents the profiles driving, walking and cycling and an alternatives flag; it does not document Longdo's mode (traffic) or type (vehicle) options, so test the routes you depend on.
// Before: Longdo RouteService (GeoJSON)
// https://api.longdo.com/RouteService/geojson/route?flon=100.53726&flat=13.72427&tlon=100.54061&tlat=13.72669&locale=th&key=YOUR_LONGDO_KEY
// After: your server, secret key
const params = new URLSearchParams({
coordinates: "100.53726,13.72427;100.54061,13.72669", // from;to as lng,lat
profile: "driving", // or walking, cycling
lang: "th",
})
const response = await fetch(`https://api.mapscale.io/v1/route?${params}`, {
headers: { "X-MapScale-Key": process.env.MAPSCALE_SECRET_KEY },
})
if (!response.ok) throw new Error(`MapScale route failed: ${response.status}`)
const { routes } = await response.json()
// routes[0].distance (meters), routes[0].duration (seconds), routes[0].geometry (LineString)Check before you ship
Display the attribution string returned in API responses and on the map. Compare results for your own addresses, place names and routes, since coverage and ranking differ between services. Run both behind a feature flag until your checks pass, then remove the Longdo script and key.