Create a table CREATE TABLE `map` ( `id` int(11) NOT NULL, `address` varchar(255) NOT NULL DEFAULT '', `location` geometry NOT NULL, PRIMARY KEY (`id`), SPATIAL KEY `idx_location` (`location`) ) insert INSERT INTO map (id, address, location) VALUES (1, 'somewhere', ST_GeomFromText('POINT(121.366961 31.190049)')); Note that you must use the ST_GeomFromText function, and POINT() contains: longitude + space + latitude Query 1. Check the latitude and longitude SELECT address, ST_AsText(location) AS location FROM map; 2. Calculate the distance between two points SELECT ST_Distance_Sphere(POINT(121.590347, 31.388094),location) AS distant FROM map; The calculated result is in meters. Note that the latitude and longitude in POINT() are now separated by commas. 3. Search for locations within 1000m and sort them from far to near Copy the code as follows: SELECT id, address, ST_Distance_Sphere(POINT(121.590347, 31.388094),location) AS distant FROM map WHERE ST_Distance_Sphere(POINT(121.590347, 31.388094),location) < 1000 ORDER BY distant; The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Solve the cross-domain problem of get and post requests of vue $http
>>: Detailed explanation of how Tomcat implements asynchronous Servlet
title: vue uses vue-meta-info to set the title an...
Since my local MySQL version is relatively low, I...
We are not discussing PHP, JSP or .NET environmen...
Why mention textarea specifically? Because the tex...
1 Start the Docker service First you need to know...
An application of CSS animation, with the same co...
1. Introduction Git is a free, open source distri...
Some properties in CSS are preceded by "*&qu...
Table of contents 1. Preparation 2. Define the gl...
Table of contents What are spread and rest operat...
We often need to summarize data without actually ...
Using the Docker run command docker run -d -p 920...
Preface This chapter uses basic Linux functions a...
The reason for writing such an article is that on...
Table of contents 1. Project requirements 2. Docu...