Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MYSQL:在地理空间查询中使用VARCHAR字段作为点_Php_Mysql_Laravel_Doctrine Orm - Fatal编程技术网

Php MYSQL:在地理空间查询中使用VARCHAR字段作为点

Php MYSQL:在地理空间查询中使用VARCHAR字段作为点,php,mysql,laravel,doctrine-orm,Php,Mysql,Laravel,Doctrine Orm,我决定检测两点之间的距离。其中一个点是静态的-35.735019 51.410041,但另一个点是由数据库字段给出的点 这是我的密码: SELECT r0_.restaurant_point AS restaurant_point_0, ST_Distance(GeomFromText('POINT(35.735019 51.410041)'), GeomFromText('POINT(r0_.restaurant_point)')) * 100 AS sclr_1 FROM res

我决定检测两点之间的距离。其中一个点是静态的-
35.735019 51.410041
,但另一个点是由数据库字段给出的点

这是我的密码:

SELECT
  r0_.restaurant_point AS restaurant_point_0,
  ST_Distance(GeomFromText('POINT(35.735019 51.410041)'), GeomFromText('POINT(r0_.restaurant_point)')) *
  100 AS sclr_1
FROM restaurants r0_
我们将
r0.restaurant\u point
存储为
VARCHAR
。以下面的字符串为例:
35.73062161548168 51.410930156707764

虽然如果我用静态值更改
r0.u点
,它会工作,但它不能用数据库字段获取度量值


是否有绑定此值的方法或其他解析方法?

要在表示点的字符串中连接列
的值,可以使用

在本例中,您只是尝试从列名本身创建点,而不是从列中的坐标创建点。您需要按如下方式更改代码:

SELECT
r0_.restaurant_point AS restaurant_point_0,
ST_Distance(
  GeomFromText('POINT(35.735019 51.410041)'), 
  GeomFromText(CONCAT('POINT(', r0_.restaurant_point, ')'))
) * 100 AS sclr_1
FROM restaurants r0_
SELECT
r0_.restaurant_point AS restaurant_point_0,
ST_Distance(
  GeomFromText('POINT(35.735019 51.410041)'), 
  GeomFromText(CONCAT('POINT(', r0_.restaurant_point, ')'))
) * 100 AS sclr_1
FROM restaurants r0_