To enable geo-searching, you must have geolocation data in your records stored in a _geoloc
attribute that contains latitude and longitude (lat and lng properties). The coordinates must be numbers, not strings.
You can refer to the below code for indexing _geoloc
using the algolia_after_create_product_object events. You can create attributes in Magento for latitude and longitude, and then retrieve the attribute values in the file:
public function execute(Observer $observer)
{
$data = $observer->getData('custom_data');
// update created_at MySQL date format to timestamp
$geoLoca = array();
$geoLoca['lat'] = 40.639751;
$geoLoca['lng'] = -73.778925;
// If a customer specifies latitude and longitude for each product using the 'lat' and 'lng' attributes, use below code
// $geoLoca['lat'] = $productObject->getLat();
// $geoLoca['lng'] = $productObject->getLng();
$data->setData('_geoloc', $geoLoca);
}