javascript - There are many plots saved in the database. The area of ​​each plot is determined by the longitude and latitude of four vertices. If the longitude and latitude of a point are known, how to determine which plot the location belongs to?

WBOY
Release: 2016-10-10 11:55:55
Original
1251 people have browsed it

Please give me an idea~

Reply content:

Please give me an idea~

Correct the demand, the po owner’s demand is [geofencing]

Solution:
PostGis+PostGreSQL
ElasticSearch/Solr

It’s probably not possible to rely solely on MySQL.
Or redesign the library

place_id name
1 Block 1
id place_id lat lng
1 1 1.1111 1.1111
2 1 1.1111 1.1111
3 1 1.1111 1.1111
4 1 1.1111 1.1111

Reference materials: http://www.cnblogs.com/LBSer/...

This seems to be a purely mathematical problem. As for the idea, you can use four small triangles T1-T4 to complete the quadrilateral into a rectangle R. It is not convenient to draw a picture now, so you can imagine it yourself. Then judge and give the point p

<code>p 在 R 内   &&   p 不在 {T1-T4} 内</code>
Copy after login

Define a point object: P[x,y], x is the latitude, y is the longitude
The four vertices of the area of ​​​​the plot are: A[x,y], B[x,y], C[x,y] , D[x,y]
The known point is: ptr[x,y]


Uh~~
You should give me a few samples~
Otherwise, it would be too wordy to teach you about geography~

Use mysql spatial functions and operations. When saving, just save a polygon area directly. Use ST_Contains function when making judgment

Use POINT, ST_AsText, POLYGON, ST_X, ST_Y, ST_DISTANCE, these are much better than directly saving longitude and latitude.

http://dev.mysql.com/doc/refm...

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!