12

I want to know if it is possible to calculate a 100 meter distance around a given point with a known latitude and longitude. I have some coordinates in a MySQL database and want to know if a specific coordinate lies in 100 meter range from a given point.

I am using the Android platform. I know only one coordinate (Longitude and Latitude) where I am standing (current location) and I want to set the distance range (say 100 meters).

I have more coordinates saved in the database and want to calculate if the other points saved in the database are in 100 meter range from my current location or not. I don't know if I can use GIS database in my application.

random
  • 9,774
  • 10
  • 66
  • 83
SilentCoder
  • 271
  • 3
  • 7
  • 16
  • What platform are you doing the calculation in? MySql or JavaScript? – Brad Dec 12 '10 at 06:46
  • At 100m, you can either (a) assume the earth is flat on that scale, and use fairly simple formulas several people have already given or (b) care about height, in which case you need a GIS database. – derobert Dec 12 '10 at 08:03

3 Answers3

8

A complete code for calculating the distance between two points given the latitude and longitude http://www.movable-type.co.uk/scripts/latlong.html

basarat
  • 261,912
  • 58
  • 460
  • 511
7

Given input is _LATITUDE, _LONGITUDE and _METERSRANGE

SELECT *, 
       ( ( ( Acos(Sin(( _LATITUDE * Pi() / 180 )) * Sin(( 
                  ` LATITUDE `* Pi() / 180 )) + 
                    Cos 
                      (( 
                        _LATITUDE * Pi() / 180 )) * Cos(( 
                    ` LATITUDE `* Pi() / 180 )) * 
                    Cos 
                      (( 
                        ( 
                             _LONGITUDE - ` LONGITUDE ` ) * Pi() / 180 ))) ) * 
           180 / Pi 
           () 
         ) * 60 * 1.1515 * 1.609344 * 1000 ) AS METERS 
FROM   MYTABLE 
WHERE  METERS <= _METERSRANGE
Pentium10
  • 204,586
  • 122
  • 423
  • 502
  • I know this was posted a long time ago - but what do the written values represent, i.e. ) * 60 * 1.1515 * 1.609344 * 1000 ) AS METERS - what is 1.1515? 1.609344? etc – tember May 14 '18 at 17:23
  • 1
    @tember 1.6 is the mile/km converter. 60 is the number of minutes in a degree; 1000 is the number of metres in a kilometre; and 1.1515 is the number of statute miles in a nautical mile. Fact: One nautical mile is the length of one minute of latitude at the equator. see this for more explanation: https://stackoverflow.com/questions/389211/geospatial-coordinates-and-distance-in-kilometers – Pentium10 May 14 '18 at 20:00
  • This answer is correct. I tested it and it works fine. – nntona Dec 02 '20 at 15:55
  • why calculate it when you can just check it with difference ? – iWasCloud Dec 28 '21 at 11:30
4

if someone still looking for answer, calculating distance is simple ( getting direction precisely is hard to calculate, if someone knows simple answer for that please do add)

So check difference between your lat-long values, change in decimal degrees to 0.001 means 111m distance. checking both latitude and longitude to decimal degrees change max 0.001 will draw a 111m radius circle around your point.

Ex. your starting point is A(Lat1,Lng1). points you want to test B(LatB,LngB) , C(LatC,LngC) .....

if: (Lat1 - 0.001) < LatB < (Lat1 + 0.001) && (Lng1 - 0.001) < LngB < (Lng1 + 0.001) == True // point B is in 100m radious.

if: (Lat1 - 0.001) < LatC < (Lat1 + 0.001) && (Lng1 - 0.001) < LngC < (Lng1 + 0.001) == False // point C is Not in 100m radious.

Decimal degrees reference https://en.wikipedia.org/wiki/Decimal_degrees

decimal degrees distance
0 1.0 111 km
1 0.1 11.1 km
2 0.01 1.11 km
3 0.001 111 m
4 0.0001 11.1 m
5 0.00001 1.11 m
6 0.000001 0.111 m
7 0.0000001 1.11 cm
8 0.00000001 1.11 mm
iWasCloud
  • 107
  • 2
  • 13