Geolocation Nearest Store Setup for 1C-Bitrix

Implementing geolocation in a Bitrix e-commerce store is a challenge every retailer with its own offline network faces. We configured this functionality for networks with 5 to 150 stores. This article covers a ready-made solution: how to make your Bitrix show the buyer the nearest store with real st

Our competencies:

Frequently Asked Questions

Implementing geolocation in a Bitrix e-commerce store is a challenge every retailer with its own offline network faces. We configured this functionality for networks with 5 to 150 stores. This article covers a ready-made solution: how to make your Bitrix show the buyer the nearest store with real stock.

A typical problem: a user visits the site, sees a product, but doesn't know if it's available in a nearby store. They start searching for addresses, calling, wasting time. Our integration solves this in seconds: geolocation access, server request, displaying the nearest point and stock. User time savings—up to 40%, conversion to offline visits increases by 15–25%.

Store Address Storage

In Bitrix, stores (warehouses/outlets) are stored in the b_catalog_store table (module catalog). Each store has fields: TITLE, ADDRESS, PHONE, SCHEDULE, GPS_N (latitude), GPS_S (longitude), ACTIVE. If GPS_N/GPS_S are empty, you need to geocode the addresses (via Yandex or Google API) and save the coordinates. For a network of 50 stores, this takes about 2 hours—once and for all.

Add coordinates programmatically:

\Bitrix\Catalog\StoreTable::update($storeId, [ 'GPS_N' => 53.9045, // latitude 'GPS_S' => 27.5615, // longitude ]); 

How Nearest Store Detection Works

The Haversine formula is the standard for calculating distance between two points on a sphere. We use either direct SQL with sorting or a PHP implementation via ORM. The first is 10 times faster for databases with 50+ stores (works in 0.001 s), the second is more flexible for integration with Bitrix components. Both options are below.

SQL query with distance sorting (MySQL/PostgreSQL):
SELECT id, title, address, gps_n, gps_s, (6371 * acos( cos(radians(:lat)) * cos(radians(gps_n)) * cos(radians(gps_s) - radians(:lng)) + sin(radians(:lat)) * sin(radians(gps_n)) )) AS distance FROM b_catalog_store WHERE active = 'Y' AND gps_n IS NOT NULL ORDER BY distance ASC LIMIT 5; 
PHP implementation via Bitrix ORM (without direct SQL):
function haversineDistance( float $lat1, float $lon1, float $lat2, float $lon2 ): float { $R = 6371; // km $dLat = deg2rad($lat2 - $lat1); $dLon = deg2rad($lon2 - $lon1); $a = sin($dLat/2)**2 + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * sin($dLon/2)**2; return $R * 2 * atan2(sqrt($a), sqrt(1-$a)); } $stores = \Bitrix\Catalog\StoreTable::getList([ 'filter' => ['=ACTIVE' => 'Y', '!=GPS_N' => false], 'select' => ['ID', 'TITLE', 'ADDRESS', 'GPS_N', 'GPS_S', 'SCHEDULE', 'PHONE'], ])->fetchAll(); usort($stores, function($a, $b) use ($userLat, $userLng) { $dA = haversineDistance($userLat, $userLng, $a['GPS_N'], $a['GPS_S']); $dB = haversineDistance($userLat, $userLng, $b['GPS_N'], $b['GPS_S']); return $dA <=> $dB; }); $nearest = array_slice($stores, 0, 3); 

Which to Choose: SQL or PHP?

Criterion SQL Query PHP Sorting
Speed (50 stores) 0.001 s 0.01 s
DB dependence MySQL/PostgreSQL only Any (ORM)
Configuration flexibility Low (fixed query) High (can filter any field)
Caching support Via Bitrix tagged cache Via Bitrix tagged cache

For projects with a large catalog (50+ stores), the SQL solution gives a 10x speed advantage—noticeable on mobile devices. If additional filtering is needed (e.g., by store type or working hours), use PHP.

AJAX Endpoint for Frontend

// /local/ajax/nearest-store.php $lat = (float)$_POST['lat']; $lng = (float)$_POST['lng']; // ... fetching and sorting ... header('Content-Type: application/json'); echo json_encode([ 'nearest' => [ 'id' => $nearest[0]['ID'], 'title' => $nearest[0]['TITLE'], 'address' => $nearest[0]['ADDRESS'], 'distance' => round($dist, 1), 'schedule' => $nearest[0]['SCHEDULE'], 'phone' => $nearest[0]['PHONE'], ], ]); 

Displaying Stock in the Nearest Store

After determining the store, you can show stock quantity for that point right in the product card. Data from b_catalog_store_product:

$stock = \Bitrix\Catalog\StoreProductTable::getList([ 'filter' => [ '=PRODUCT_ID' => $productId, '=STORE_ID' => $nearestStoreId, ], 'select' => ['AMOUNT'], ])->fetch(); $inStock = $stock && $stock['AMOUNT'] > 0; 

UI and UX

Typical interface: a floating block in the header "Nearest store: [Name], [distance] km" or a widget on the product page "Availability in stores". A "Detect" button triggers the geolocation request. If the user denies access, you show a store list with address search. For a full map, connect Yandex.Maps JS API or Google Maps API and place markers for all points.

Additionally: you can implement automatic store detection by IP (via Sypex Geo service)—this works if the user didn't grant geolocation access. Accuracy—up to 50 km, but sufficient for large cities. This is our IP city detection Bitrix solution.

Implementation Steps

  1. Audit current stores—check GPS coordinate population.
  2. Geocoding—automatically determine coordinates for stores without GPS_N/GPS_S.
  3. Create AJAX endpoint—fetch nearest stores with stock.
  4. Develop widget—block on product page or header.
  5. Integrate with map (optional)—Yandex.Maps or Google Maps.
  6. Test and cache—set up tagged cache for fast performance.
  7. Documentation and handover—detailed API description and settings.

How to Get Coordinates if GPS_N/GPS_S Are Empty

Use Yandex Geocoding API (free 25,000 requests/day) or Google Maps Geocoding API. For Bitrix, you can write an agent that daily fills coordinates for empty stores. Example request: https://geocode-maps.yandex.ru/1.x/?geocode=Moscow,Tverskaya,1&format=json. Save the obtained coordinates via \Bitrix\Catalog\StoreTable::update().

What's Included

Stage Result
Geocoding and coordinate filling All stores with coordinates in DB
AJAX endpoint for nearest store API method with sorting and caching
"Nearest store" widget Ready block for header/product card
Stock output for nearest warehouse Display availability in selected store
Map integration (optional) Interactive map with markers
Documentation and training PDF guide + consultation

Cost is calculated individually after project analysis. Budget savings compared to development from scratch—up to 60% (from $500 to $1,200). Timeline—from 3 days to 2 weeks, depending on integration complexity (1C presence, number of points). With over 7 years in Bitrix development and 50+ successful integrations, we deliver reliable solutions. Contact us for a consultation—we will evaluate your project in one business day. Get a ready-made solution with compatibility guarantee with 1C and Marketplace.

Our Bitrix geolocation API integration ensures seamless store distance sorting using the Haversine formula. The nearest store widget can be customized to display stock information. For multi-warehouse networks, our Bitrix nearest warehouse feature optimizes logistics.