Closed danharper83 closed 2 months ago
Same. I'm also looking for what.
Would be nice to see an option to save ith separately or as POINT()
You can do this with the current plugin but when it comes to the distance filter it will still use the PHP library to calculate the distance.
protected $casts = [
'lat_lng' => Point::class,
];
protected $appends = [
'lng',
'lat',
'location',
];
public function getLngAttribute(): float
{
$lng = $this->lat_lng->longitude ;
return $lng;
}
public function getLatAttribute(): float
{
$lat = $this->lat_lng->latitude;
return $lat;
}
/**
* Get the location attribute.
*/
public function getLocationAttribute(): array
{
return [
'lat' => (float) $this->lat,
'lng' => (float) $this->lng,
];
}
Just to note, In did this because I already had the fields setup as points in the model, the plugin doesn't use any SQL functionality for distance filtering. So if you haven't started with points like I had then there's probably no need to use points.
I think to make the plugin work with SQL distance functions etc would take a lot more work and possibly add a dependency on something like https://github.com/asanikovich/laravel-spatial which may not be desirable.
Oh, that's amazing and helps a lot. Thanks.
Same for me. I already use POINT()
for my data structure and calculation in Laravel. I just want to display a map in Filament, where I can save coordinates back into the database in the correct format.
Marking as complete as I think it would be a different request to completely adopt a point solution.
I'm using mysql GeoSpatial point fields in my model already and don't really want to duplicate them into separate lat lng fields so I've modified the radius filter with a patch.
Is something you think may be worth adding as a feature of this plugin?