Integrating Maps into a Business Website: Locations and Branch Finders

A customer opens your contact page on a phone outside the building. They need the correct branch, the entrance and current opening hours. A decorative map with one anonymous pin does not answer those questions. Build the page around the branch information first, then use an interactive map to show where each location sits.

TrackAsia GL JS renders interactive vector maps in the browser, and its quickstart documents the streets v2 style used below.[3] Your own branch directory supplies the names, addresses and checked coordinates. The map service provides geographical context; it does not know that your branch moved last week or that its receiving entrance is around the corner.

Start with a page that still works without the map

A useful minimum contains a location heading, a readable address, an opening-hours statement where known and a way to select another branch. Keep this information in normal HTML. If WebGL is unavailable or a script fails, the visitor should still be able to identify the business premises.

Give every branch a stable ID, independent from its display name. Names change, and two locations can share a trading name. Store coordinates as named longitude and latitude values. Check the actual entrance for customer-facing premises; a point returned for a whole shopping complex may be insufficient for a clinic on a particular side of the building.

The demonstration below deliberately labels its points as examples. Replace them with your verified branch records before publishing. Do not present sample opening hours, a sample address or a nearby landmark as a real outlet. A map that loads successfully has passed a rendering test, not a branch-data verification test.

Copy a complete two-location page

Save this as branches.html and open it in a current browser with internet access. It includes the stylesheet and JavaScript library, a map with a defined height, a text list and two selection buttons. The documented public_key is limited and for testing only; use your configured account key when deploying.[3]

<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Demonstration locations</title>
<link rel="stylesheet" href="https://unpkg.com/trackasia-gl@2.0.1/dist/trackasia-gl.css">
<style>body{margin:0;font:16px/1.6 system-ui;color:#17324d}main{max-width:960px;margin:auto;padding:16px}#map{height:52vh;min-height:300px;max-height:520px}button{padding:12px;margin:8px 8px 8px 0;font:inherit}li{margin-bottom:12px}</style></head><body><main><h1>Demonstration locations</h1><p>Example points only. Replace with verified branch names, addresses and entrances.</p><ul id="list"></ul><p id="status" role="status">Loading map</p><div id="map" aria-label="Demonstration locations"></div></main>
<script src="https://unpkg.com/trackasia-gl@2.0.1/dist/trackasia-gl.js"></script>
<script>
const branches=[{id:'demo-A',name:'Example point A',lng:106.694945,lat:10.769034},{id:'demo-B',name:'Example point B',lng:106.7218,lat:10.7952}];
const list=document.querySelector('#list');
for(const branch of branches){const li=document.createElement('li');const button=document.createElement('button');button.textContent=branch.name;button.type='button';button.onclick=()=>selectBranch(branch.id);li.append(button);list.append(li);}
let map;const markers=new Map();
function selectBranch(id){const b=branches.find(b=>b.id===id);if(!map||!markers.has(id))return;for(const marker of markers.values())marker.getPopup().remove();map.flyTo({center:[b.lng,b.lat],zoom:14});markers.get(id).togglePopup();}
try{map=new trackasiagl.Map({container:'map',style:'https://maps.track-asia.com/styles/v2/streets.json?key=public_key',center:[106.70,10.78],zoom:12});
for(const branch of branches){const text=document.createElement('p');text.textContent=branch.name;const marker=new trackasiagl.Marker().setLngLat([branch.lng,branch.lat]).setPopup(new trackasiagl.Popup().setDOMContent(text)).addTo(map);markers.set(branch.id,marker);}
const bounds=new trackasiagl.LngLatBounds();branches.forEach(b=>bounds.extend([b.lng,b.lat]));map.fitBounds(bounds,{padding:55,maxZoom:14});map.on('load',()=>document.querySelector('#status').textContent='Map ready');map.on('error',()=>document.querySelector('#status').textContent='Map unavailable; the location list remains above.');
}catch(error){document.querySelector('#status').textContent='Map unavailable; the location list remains above.';}
</script></body></html>

The initial view fits both demonstration points. Selecting a button moves the camera to that point and opens a popup. The popup receives a DOM node whose content is assigned with textContent, so the name is treated as text rather than executable markup. The list and buttons are application code; they are not a branch-management service supplied automatically by the map.

If opening a local file is blocked by your browser’s security policy, serve its directory with python3 -m http.server 8080 and visit http://localhost:8080/branches.html. This is a local testing option, not a requirement to add Python to a production website. A CMS deployment normally places the same HTML, CSS and JavaScript within its own asset pipeline.

Understand which values belong to which layer

center and setLngLat receive [longitude, latitude] arrays in the example. The branch records use named lng and lat fields to make the conversion visible. Reversing the values can send a map to the wrong region or outside usable latitude bounds. Validate the data before using it, rather than trying to diagnose the mistake from an empty canvas.

The style URL describes the basemap’s appearance and resources. It is not your branch database. Updating a branch in your CMS should update its record and marker, not require editing the vendor’s style. Likewise, adding a marker does not publish a business listing in a search engine or submit the branch to a separate consumer map directory.

The map container’s height is essential. A canvas can exist in the DOM with no visible area if the surrounding page gives it zero height. The example uses a bounded viewport-relative height so the page retains room for its text list on a phone. If the map is initially hidden in a tab or modal, resize it after the container becomes visible.

Move the demonstration data into your CMS

Once the basic page works, replace the hard-coded array with your own branch feed. A compact record can contain id, name, address, lng, lat, hours, accessNote, pageUrl and updatedAt. These are proposed application fields, not a TrackAsia response schema. Omit fields you cannot keep accurate rather than filling them with plausible defaults.

Read the feed once for the current view and reuse the parsed records for both list and markers. That prevents a common inconsistency where the map shows a closed branch while the text list has already been updated. Validate IDs, coordinates and URL destinations at publication time. If the branch has a temporary closure, make that state explicit in the list and decide whether it remains selectable.

Give the update workflow an owner. Staff responsible for premises can confirm an entrance; a content editor can maintain hours and access notes; a developer can ensure the feed and page use the same version. The map API cannot replace those responsibilities. Record when information was last checked so a future editor knows whether a branch is current or merely inherited.

Make selecting a location comfortable on a phone

The customer should be able to scroll past the map and reach the address list. Test that interaction on a real touch device, not only a narrow desktop window. Keep branch buttons readable, with enough spacing to avoid accidental selection, and do not make hover the only way to discover a location’s name.

Keyboard users should be able to select the same locations through buttons. The text list is also valuable for screen readers because map geometry alone is not a useful reading order. Use a meaningful map label and ordinary headings; do not put the only address inside a popup that requires a pointer to open.

If you add “near me”, request browser location only after that action. Explain why it is needed and offer a region selector if permission is refused. Do not force visitors to share their position just to read your branches. For an initial shortlist, straight-line proximity may be useful, but label it accordingly. A road travel-time ranking requires a separate routing or matrix workflow and should not be implied by sorting markers.

Grow beyond a handful of points only when needed

A few branches are straightforward markers. Hundreds of overlapping pins need another presentation. Start by filtering the list by province, service type or area; the visitor often knows one of those before they know an exact coordinate. Keep the list count and visible map points in agreement.

If clustering is appropriate, implement and test it with the renderer’s documented GeoJSON capabilities rather than creating thousands of independent popup objects. A cluster represents several records and needs an interaction that reveals them; it should not pretend to be one branch. Test zoom behaviour, mobile tapping and the ability to reach an individual result from the list.

Do not call address search every time the branch list renders. Your verified branch coordinates should normally come from your directory, subject to your data rights and update process. Search is useful while maintaining or discovering a location, not automatically necessary for every visitor viewing an already verified branch.

Protect the integration without hiding public information

A browser key is visible to the browser. Do not embed a backend secret in this HTML and assume minification protects it. Use the account’s supported restrictions and confirm their actual behaviour for your production domain and test environment. Keep the limited public key for small demonstrations, not as a production service arrangement.

Review Content Security Policy when the site blocks scripts, styles, workers or map resources. TrackAsia’s guides include CSP guidance.[3] Follow the resources your chosen style and library actually need; do not solve a blocked dependency by disabling security policy for the entire website. Pin the library version after testing instead of allowing a future latest release to change production unexpectedly.

Treat CMS text as untrusted input. The example uses textContent for names, and that pattern should extend to addresses and access notes. If rich content is genuinely required, sanitise it with an appropriate maintained tool. Validate branch links against permitted destinations before rendering them as anchors, and keep map attribution unobscured.

Diagnose an empty or partially working map

If no map appears, check container dimensions first, then whether the library and CSS loaded. An undefined trackasiagl points to script loading or execution order. A map frame without basemap content calls for checking style and tile requests, key errors and CSP messages in the browser console. Do not paste a secret key into a public support screenshot.

If the map is visible but the marker is wrong, inspect longitude and latitude order and verify the stored branch point. If selecting a location does nothing, check that the stable ID matches the record used to build the marker. If popups look unstyled, confirm that the library CSS was not removed by a CMS optimisation tool.

For slow pages, avoid creating a map repeatedly on every UI render. Keep one instance for the component and clean up event handlers and the instance when the component is removed. Consider loading the map when its section approaches the viewport, but keep the text list available immediately. Measure behaviour on representative phones before adding animation or extra layers.

Try the source: Branch location map

Select a list item to open its map popup; replace illustrative points with verified branch information.

API examples use the limited public_key; the image captures a run of the source below.

Unzip, run python3 -m http.server 8080 in the extracted folder, then open http://localhost:8080/index-en.html. Vietnamese and English READMEs are included; no npm or build step is needed.

Download complete source ZIP

Branch location map
Tap the image to open full size.

Verify the public branch page after every important change

Check desktop and narrow phone layouts, then select every branch. Confirm names, addresses, actual entrances, links and any published hours. Test a failed map request and a denied location permission if the feature uses it. A branch page should remain useful in both situations.

If you add LocalBusiness structured data, use genuine information appropriate to the business and keep it aligned with the visible page. Neither embedding a map nor adding structured data guarantees a search ranking or a Local Pack position. The immediate goal is simpler and measurable: visitors can identify the correct branch and understand how to reach it.

For a production discussion with TrackAsia, provide the expected map usage, number of branches, update method, required environments and any separate address or route services. That lets the team confirm the relevant key configuration, service scope and commercial terms without confusing a branch map with an entire logistics application.

Sources

[3] https://docs.track-asia.com/guides