开发者

google map api v3.. tell whether point 1 and 2 are near each other

开发者 https://www.devze.com 2023-01-26 16:10 出处:网络
Hi i have two google map coordinates... point 1: \"1.326631,103.861297\" and point 2: \"1.326116,103.860873\".

Hi i have two google map coordinates...

point 1: "1.326631,103.861297" and point 2: "1.326116,103.860873".

Is there any way to do a javascript function to tell whether point 1 & 2 is near to each other probably by through a r开发者_运维问答adius circle? Thanks


Here are the calculations, I wrote a function in SQL for calculating radial miles from two points based on latitude and longitude. You could probably use it as a basis for converting it to Javascript if needed.

declare @DegToRad as float
declare @Ans as float
declare @Miles as float

set @DegToRad = 57.29577951
set @Ans = 0
set @Miles = 0

set @Ans = SIN(@lat1 / @DegToRad) * SIN(@lat2 / @DegToRad) + COS(@lat1 / @DegToRad ) * COS( @lat2 / @DegToRad ) * COS(ABS(@long2 - @long1 )/@DegToRad)
set @Miles = 3959 * ATAN(SQRT(1 - SQUARE(@Ans)) / @Ans)
set @Miles = CEILING(@Miles)

return @Miles

Edit: By the way, there's a good open source control that you can use in ASP.net on Codeplex.

http://googlemap.codeplex.com/

0

精彩评论

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

关注公众号