Store Locator for OpenCart 4: A Find-a-Store Page With Search, Near-Me Sorting and a Free Map (Free Extension)
A free OpenCart store locator built on OpenCart's own locations: search by city or postcode, sort by distance with one tap, and show each store on a map with no API key.

Shoppers who want to see a product before buying, pick up an order or get a repair need one thing from your site: which store is closest, and is it open? OpenCart 4 already lets you save store locations, but it only prints them as a plain list on the Contact Us page, with no search, no map and no way to find the nearest one.
This free extension adds an OpenCart store locator page. It reads the locations you already keep in OpenCart, lets visitors search by city or postcode, sorts stores by distance with one tap on “Use my location”, and shows the selected store on a map that needs no API key. Tested on OpenCart 4.1.0.4.
Download: storelocator.ocmod.zip (OpenCart 4.0.2.x to 4.1.x, free, no core file changes)

What the store locator extension does
- Adds a Find a store page with every location from System > Localisation > Store Location, or only the ones you tick.
- Shows each store’s address, phone number, opening hours, comment and image, with Directions and Call buttons.
- Filters the list as the visitor types a city, postcode or store name.
- Sorts stores by distance when the visitor taps Use my location, in miles or kilometers. The position stays in the browser.
- Shows the selected store on an OpenStreetMap map. No Google Maps API key or billing account.
- Adds a “Find a store” link to the footer and a
/store-locatorSEO URL. - Adds schema.org
Storestructured data for each location.
Install the extension
- Download
storelocator.ocmod.zip. - Go to Extensions > Installer, click Upload and choose the zip.
- Go to Extensions > Extensions, choose Modules, find Store Locator and click Install.
- Click Edit, switch Status on and click Save.
Add your stores
The stores are OpenCart’s own locations, so there is nothing new to learn. Go to System > Localisation > Store Location and add one entry per store: name, address, telephone, opening times and an optional image and comment.
The one field that matters for the map and the distance sorting is Geocode. OpenCart only says “Please enter your store location geocode manually”, so enter it as latitude,longitude, for example 41.8781,-87.6298. In Google Maps, right-click the store and click the coordinates to copy them. In OpenStreetMap, right-click and choose “Show address”.

A store without a usable geocode is still listed with its address, hours and a Directions button that searches for the address. It just has no map and no distance.
Settings

- Page heading and Introduction, per language.
- Stores to show: tick the locations to list. Leave every box unticked to show all of them. Each row shows “Geocode OK” or a warning, with an edit button.
- Footer link: adds “Find a store” to the Information column of the footer.
- “Use my location” button and Distance unit (miles or kilometers).
- Map: the OpenStreetMap map next to the list.
- Store structured data: the schema.org markup described below.
How the OpenCart store locator works
It reads OpenCart’s own locations
There is no extra table to keep in sync. The model reads the core location table, filtered to the ticked stores:
public function getLocations(array $location_ids = []): array {
$sql = "SELECT `location_id`, `name`, `address`, `telephone`, `geocode`, `image`, `open`, `comment` FROM `" . DB_PREFIX . "location`";
$location_ids = array_filter(array_map('intval', $location_ids));
if ($location_ids) {
$sql .= " WHERE `location_id` IN (" . implode(',', $location_ids) . ")";
}
$sql .= " ORDER BY `name` ASC";
return $this->db->query($sql)->rows;
Because the core geocode field is free text, the controller only accepts a real latitude and longitude:
private function parseGeocode(string $geocode): array {
if (preg_match('/^\s*(-?\d{1,2}(?:\.\d+)?)\s*,\s*(-?\d{1,3}(?:\.\d+)?)\s*$/', $geocode, $match) && abs((float)$match[1]) <= 90 && abs((float)$match[2]) <= 180) {
return [(float)$match[1], (float)$match[2]];
}
return [];
“Use my location” never leaves the browser
The button asks the browser for the visitor’s position and works out the straight-line distance to each store with the haversine formula. Nothing is sent to your server and nothing is stored, so there is no personal data to declare beyond what the browser itself asks permission for:
// Distance on a sphere (haversine). Runs only in the browser; the position is never sent anywhere.
function distance(lat1, lng1, lat2, lng2) {
var r = labels.unit === 'mi' ? 3958.8 : 6371, rad = Math.PI / 180;
var a = Math.pow(Math.sin((lat2 - lat1) * rad / 2), 2) + Math.cos(lat1 * rad) * Math.cos(lat2 * rad) * Math.pow(Math.sin((lng2 - lng1) * rad / 2), 2);
return 2 * r * Math.asin(Math.sqrt(a));
If the visitor says no, or the browser can’t get a position, the page shows “We could not get your location. Search by city or postcode instead.” Browsers only offer location on HTTPS pages (and on localhost while you develop).
A map without an API key
The map is OpenStreetMap’s embed page in an iframe, pointed at the selected store. Clicking Show on map on another store only changes the iframe’s address:
var lat = parseFloat(store.dataset.lat), lng = parseFloat(store.dataset.lng), d = 0.01;
map.src = 'https://www.openstreetmap.org/export/embed.html?bbox=' + [lng - d * 1.6, lat - d, lng + d * 1.6, lat + d].map(function (n) { return n.toFixed(5); }).join('%2C') + '&layer=mapnik&marker=' + lat.toFixed(5) + '%2C' + lng.toFixed(5);
The map loads from openstreetmap.org, so add it to your privacy policy, and switch the map off if you would rather not load third-party content. A link such as /store-locator#store-3 opens the page with that store selected.
Structured data for each store
Each location is described as a schema.org Store with its name, address, phone and coordinates. This helps search engines and AI assistants understand which addresses belong to your business. It doesn’t guarantee any special search result, and for your main locations a Google Business Profile matters more:
$store = [
'@type' => 'Store',
'@id' => $schema_url . '#store-' . (int)$location['location_id'],
'name' => $name,
'address' => preg_replace('/\s*\n\s*/', ', ', trim($address)),
'url' => $schema_url . '#store-' . (int)$location['location_id']
];
if ($telephone !== '') {
$store['telephone'] = $telephone;
}
if ($geo) {
$store['geo'] = ['@type' => 'GeoCoordinates', 'latitude' => $geo[0], 'longitude' => $geo[1]];
}
if ($image) {
$store['image'] = $image;
}
$schema[] = $store;
The footer link
A catalog/view/common/footer/before event adds the page to the footer’s Information links, so it works with the default theme and with themes that keep the core footer data, such as the Webocreation Theme:

Search and phones
Typing filters the list at once. Searching “san” leaves only the San Francisco store, and the map jumps to it:

On phones the list comes first and the map moves below it. Show on map scrolls down to the map.

What we found when testing
We tested on OpenCart 4.1.0.4 with five demo locations: four with coordinates and a weekend pop-up with no geocode.
- With the browser position set to Milwaukee, “Use my location” put Chicago first at 81 miles, then New York at 732 and Austin at 1,036. The pop-up with no geocode went to the end with no distance.
- When the location permission was denied, the page showed the fallback message and kept the alphabetical list.
- OpenStreetMap’s embed draws its map with WebGL. Headless Chrome without a GPU showed “your browser does not support WebGL” instead of the map. Normal browsers are fine.
- The extension adds the
store-locatorkeyword on install and removes it on uninstall. Pretty URLs such as/en-gb/store-locatoronly work after you rename OpenCart’s.htaccess.txtto.htaccess, the same as for every other SEO URL. - Uninstalling removes the footer event, the SEO URL and the settings. Your locations stay, because they belong to OpenCart.
Limitations
- Distances are straight lines, not driving distances. The Directions button hands the trip to Google Maps.
- Search matches text in the name and address. It doesn’t geocode a postcode, so “60602” won’t find a store whose address says “60601”.
- The map shows one store at a time, not every store as pins on one map.
- Opening hours are the free-text “Opening Times” field, so the page can’t say “open now”.
- If your store gets heavy traffic, read OpenStreetMap’s tile usage policy before relying on the embed.
Related posts
- WhatsApp Chat Button for OpenCart 4: let visitors message the store before they visit.
- SEO Toolkit for OpenCart 4: audit the catalog, bulk-edit SEO URLs and meta tags, and add structured data to the rest of the store.
- Webocreation Theme for OpenCart 4: the free theme used in these screenshots.







