Home >Backend Development >PHP Tutorial >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?
Please give me an idea~
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>
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...