Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
How to determine whether geocache(latitude, longitude) to the radius? - bug-code.com Q&A

How to determine whether geocache(latitude, longitude) to the radius?

0 like 0 dislike
115 views
Ie there is a circle on the map centered, for example, [51.526613503445766, 46.02093849218558]

has a radius of 5 km.


You want to determine which points are included in this radius and which are not.


A library for determining the distance found.
code.google.com/p/geopy
asked by | 115 views

7 Answers

0 like 0 dislike
Consider the distance from the point to the center of your circle, if the distance is less than or equal to 5 km, then includes if it means more not included.
answered by
0 like 0 dislike
Why a library? There is a formula in 1 line, defines the distance in meters.
$distance = 2 * asin(sqrt( pow(sin(deg2rad( ($lat1-$lat2) / 2)), 2) +
cos(deg2rad($lat1)) * cos(deg2rad($lat2)) *
pow(sin(deg2rad(($lng1- $lng2) / 2)), 2))) * 6378245;
\r
If the points are stored in the database — do not select all, but only in certain limits. And for them to have to calculate the distance
answered by
0 like 0 dislike
Do not do this to begin with. What are the requirements on the accuracy and speed of the algorithm? How many points should be checked for occurrence in one circumference? All La still you slusanschi the Land, and to the relief? Do you understand that the circle on the map will not look like a circle?
answered by
0 like 0 dislike
In General, the algorithm is such that there is a database with users, each user has field coordinates lat, lon
need for example to find all users in a square 20 km
\r
example for django
\r
 dist = 20 #distance 20 km mylon = 51.5289156201 # longitude of the center mylat = 46.0209384922 # latitude lon1 = mylon-dist/abs(math.cos(math.radians(mylat))*111.0) # 1 degree of latitude = 111 km lon2 = mylon+dist/abs(math.cos(math.radians(mylat))*111.0) lat1 = mylat-(dist/111.0) lat2 = mylat+(dist/111.0) profiles = UserProfile.objects.filter(lat__range=(lat1, lat2)).filter(lon__range=(lon1, lon2)) 
answered by
0 like 0 dislike
Optimization search by joining dots to form a square for Mysql
\rwww.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL
answered by
0 like 0 dislike
If I understand you correctly, just from the circle equation (x — x_0)^2 + (y — y_0)^2 <= R^2 where x_0 and y_0 are the coordinates of the center of your coordinate system. Just take the coordinates of the point and check.
answered by
0 like 0 dislike
There is a small but still a difference between "included in the radius" and "is square". Square the decision easier for him to do serious GIS artillery is not needed, and is lightning fast.
\r
Here's how:
0. Assume that the coordinates of the point in radians you have stored in the database, the fields lat and lng.
1. Create one index on both fields to speed up queries.
2. In the code translate 10 km in radians (I think, one meter 0,1988 radian, but check).
3. To determine which points are in a square with sides 10 km from a given point in the center, write the following query:
\r
\r
SET @lat = 51.526613503445766; # given in the statement SET @lng = 46.02093849218558; SET @half= [10 km in radians] / 2 ; SELECT id FROM points WHERE lat BETWEEN @lat - @half AND @lat + @half AND lng BETWEEN @lng @half AND @lng + @half; 

\r
The first 3 lines (SET) it is necessary to remove and replace them in the query to use the variables from your language of application server (Python, as I understand it).
\r
If you need an exact value (because the earth is not a smooth ball) or radius, see the decisions other authors.
answered by
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers

0 comments

12.7k users

24,788 questions
46,220 answers
0 comments
12,719 users