I am trying to store Google Map Circle data in MySql Database. I choose text
data type to store Center Coordinate and int
to store radius of the center. Now I am using below code to fetch data from those column.
$zone = RestaurantZones::whereRaw( "ST_Distance(circle_coordinates, ?) <= radius", [$point] )->pluck( 'id' );
I am getting below error.
IlluminateDatabaseQueryException: SQLSTATE[22023]: Invalid parameter value: 3037 Invalid GIS data provided to function st_distance.
How can I store Google Map Circle data in MySql Database ?
2
Answers
It’s pretty clear from the error shown, to store and retrieve this kind of data, you should use MySQL’s spatial data types and functions.
"(Just for revision) Imagine you have a map with circles on it, like the Google Map circles. Each circle has a center (the middle point) and a radius (how big it is).
Having a table that uses spatial data types
ST_GeomFromText
function to create a point from the center coordinates.Ensure that your circle_coordinates column in the RestaurantZones table is defined as a spatial data type into your Model.
if you are using this package
then model should looks like this.
In your migration field type should be in the point
And
If you’ve ensured that the circle_coordinates and radius columns are correctly defined, and you’re passing a valid Point object for the $point variable, you should be able to use ST_Distance without encountering the "Invalid GIS data" error. If the issue persists, you may want to check the actual data in your database to make sure there are no anomalies or inconsistencies in the spatial data.