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
Everyone may be familiar with the select drop-dow...
Page directory structure Note that you need to mo...
Later, I also added how to use Jupyter Notebook i...
1. Cleaning before installation rpm -qa | grep jd...
Table of contents 1. Introduction to UDP and Linu...
Timer Effects: <div> <font id='timeC...
This article example shares the specific code of ...
After Vmvare sets the disk size of the virtual ma...
Table of contents Initialize computed Dependency ...
1. The relationship between fonts and character d...
Basic syntax: <input type="hidden" na...
Table of contents defineComponent overload functi...
Recently, I encountered a problem in the process ...
tcpdump is a flexible and powerful packet capture...
<br />What is web2.0? Web2.0 includes those ...