doq1969 2012-10-26 23:55
浏览 30
已采纳

用hasrsine和float计算距离...有点工作

I'm using a haversine query to pull locations nearest to a lat/lon provided from a mobile app.

The query looks like this:

SELECT *,(((acos(sin(($latitude *pi()/180)) * sin((`lat`*pi()/180))+cos(($latitude *pi()/180)) * cos((`lat`*pi()/180))* cos((($longitude - `lon`)*pi()/180))))*180/pi())*60*1.1515) AS dist_x 
FROM `work_places`
HAVING dist_x <= '1'
ORDER BY dist_x ASC
LIMIT 10

This is working just fine and I'm getting exactly the locations I should be getting.

The problem is in converting dist_x to something readable by the users. Right now, lets say dist_x reads as: 0.00996273036944 (floatval and as a string shows the same so it's converting properly)

Since the query is searching withing 1 mile, I am trying to convert this to feet so I'm dividing dist_x by 5280.

       $distance = (float)( $dist_x / 5280 );

What I get back is $distance = 1.88688075179E-6

What am I doing wrong?

  • 写回答

2条回答 默认 最新

  • drxm72811 2012-10-27 00:18
    关注

    I may be missing something, but if you want to convert miles to feet, don't you want to multiply by 5280 instead of dividing?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度