简体   繁体   中英

How to convert result distance of haversine formula in mysql

I got query witch gives me a distance.

(6378 * acos(cos(radians(".$lat.")) * cos(radians(p1.lat)) * cos( radians(p1.lng) - radians(".$lng.")) + sin(radians(".$lat.")) *
                sin(radians(p1.lat)))) AS distance

Result is for example: 0.0000972987365289 how to get normal human readable in kilometers ?

use the ST_DISTANCE_SPHER E which gives back meters

SELECT

ST_DISTANCE_SPHERE(POINT(".$lng.", ".$lat."), POINT(v, p1.lat)) / 1000 AS distance

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM