douhao5280 2011-05-16 22:02
浏览 78

地理距离搜索MYSQL

I'm doing a geo search with mysql using the spatial extension. FOr that i did a stored procedure (thats work really well when i tri on command line in mysql like that

mysql> CALL test2(GeomFromText('POINT(-0.93961472 43.52843475)'),0.6 );

DROP PROCEDURE `test2`//
CREATE DEFINER=`root`@`localhost` PROCEDURE `test2`(IN center2 point,IN dist int)
BEGIN
SET @center = center2;
SET @radius = dist;

SET @bbox = CONCAT('POLYGON((', 
 X(@center) - @radius, ' ', Y(@center) - @radius, ',', 
 X(@center) + @radius, ' ', Y(@center) - @radius, ',', 
 X(@center) + @radius, ' ', Y(@center) + @radius, ',', 
 X(@center) - @radius, ' ', Y(@center) + @radius, ',', 
 X(@center) - @radius, ' ', Y(@center) - @radius, '))' 
);

SELECT professionnels.*, AsText(coord) 
FROM professionnels 
WHERE Intersects( coord, GeomFromText(@bbox) ) 
AND SQRT(POW( ABS( X(coord) - X(@center)), 2) + POW( ABS(Y(coord) - Y(@center)), 2 )) < @radius limit 20;
end

But the problem is that i need to call that from php. and when i do it, an error is return said that

PROCEDURE test2 can't return a result set in the given context

So.. How can i use a turn around to return a set of data ?

Thanks

  • 写回答

1条回答 默认 最新

  • dongshendie8849 2011-05-16 22:34
    关注

    You can change the last part into

    /*delete all rows from temp_table*/
    DELETE FROM temp_table WHERE temp_table.somefield is not null;
    
    INSERT INTO temp_table
      SELECT professionnels.*, AsText(coord) 
      FROM professionnels 
      WHERE Intersects( coord, GeomFromText(@bbox) ) 
      AND SQRT(POW( ABS( X(coord) - X(@center)), 2) 
          + POW( ABS(Y(coord) - Y(@center)), 2 )) < @radius limit 20;
    

    Then you can select from the temp_table and find resultset there.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题