set @meterR = 111195;
set @range = 2300 / @meterR;
select id,( st_distance(shape,point(-7.747347,110.404036)) * @meterR ) as distance from locations
where st_distance(shape,point(-7.747347,110.404036)) < @range
and locationable_type = 'App\\Models\\Perawat'
$query->havingRaw("distance < locations.range*1000");
CREATE TABLE IF NOT EXISTS `locations` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`shape` point NOT NULL,
`locationable_type` varchar(100) NOT NULL,
`locationable_id` int(10) unsigned NOT NULL,
`alamat` varchar(2000) NOT NULL,
`range` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
SPATIAL KEY `point_spatial` (`shape`),
KEY `locations_locationable_id_index` (`locationable_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=22 ;