开发者

Calculate 100 meter distance when the latitude and longitude is a known point

开发者 https://www.devze.com 2023-01-30 07:37 出处:网络
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

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 开发者_JS百科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.


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


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号