I have these data:
latitude: 50.223137
longitude: 18.679558
and now I would like to create a special function in PHP which will be able to calculate minimum lat & long and maximum lat & long which are nearer than 50 km. Finally I would like to get 4 parameters and I would like to use these parameters in simple SQL query: SELECT * FROM table WHERE lat >= [min_lat] AND lng >= [min_lng] AND lat <= [max_lat] AND lng <= [max_lng];
I know, I can do it using only one sql query: latitude/longitude find nearest latitude/longitude - complex sql or complex calculation but I have 20.000.000 records in my database now and it still grow up. I also have to search in my sql database other things so I want calculate everything based on PHP and then search in sql in that way: SELECT * FROM table WHERE lat >= [min_lat] AND lng >= [min_lng] AND lat <= [max_lat] AND lng <= [max_lng];
because I think - this is faster way.
I also found this function: https://www.geodatasource.com/developers/php and this is great but I want create that function in other way - I want declare as argument: lat, lng and distance (for example: 50 km). finally I would like to get 4 parameters - min_lat, min_lng, max_lat, max_lng.
Anybody can help me to create this function?
Thanks.