doufen1933 2015-01-19 22:45
浏览 142

ST_WITHIN()不返回任何结果

I'm working on the problem of finding all customers within so many miles of a specific lon/lat and returning a list of those customers in an array. I'm now pretty versed in the Haversine formula and the old way of doing that with boundaries in MySQL. However, updating to version 5.6 of MySQL, I'm now attempting to use the function ST_WITHIN() to produce the same result.

I'm following a tutorial posted here:

http://rutweb.com/using-the-new-spatial-functions-in-mysql-5-6-for-geo-enabled-applications/

My code so far looks like so:

$lat = 40.2808380;
$lon = -111.6573890;
$distance = $row['RadialMiles']; // radius of bounding circle in miles

$rlon1 = $lon - $distance/abs(cos(deg2rad($lat))*69);
$rlon2 = $lon + $distance/abs(cos(deg2rad($lat))*69);
$rlat1 = $lat - ($distance/69);
$rlat2 = $lat + ($distance/69);

$query = "SELECT astext(Position), Firstname, Lastname FROM Account
 WHERE systemAccountID = '$systemAccountID'
 AND st_within(Position, envelope(linestring(point(:rlon1, :rlat1), point(:rlon2, :rlat2))))";

    try {
        $stmt = $con->prepare($query);
        $stmt->execute(array('rlon1' => $rlon1,'rlon2' => $rlon2,'rlat1' => $rlat1,'rlat2' => $rlat2));
        $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
    } catch (PDOException $e) {
        throw $e;
    }

    print_r($result);

Right now the array produces an empty result, when I know it should return 2 results.

FYI, you can just assume my table has 3 columns: Firstname, Lastname, and Position. Position is type point and contains something like: POINT(38.8026085 -116.4193878)

I've been working with this all day and using the spatial functions has been... frustrating for me. Any help would be appreciated.

  • 写回答

1条回答 默认 最新

  • duanjiao5543 2015-01-19 23:53
    关注

    For all those who want to use this tutorial for mysql's ST spacial functions, just know that the tutorial lists out the points in a (lon, lat) format instead of (lat, lon). This is the reason I had trouble getting a returned value.

    评论

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭