将MySQL的POINT转换为PHP中的文本 [英] Convert MySQL's POINT to text in PHP
问题描述
使用PHP,如何将POINT
数据类型中的值转换为类似POINT (-34.601020 -58.371020)
的字符串(最好使用WKT或GeoJSON输出)
Using PHP, how can I convert a value in POINT
datatype to a string like POINT (-34.601020 -58.371020)
(an ouput in WKT or GeoJSON is preferable)
如果我回显原始值,我会得到奇怪的字符.
If I echo the raw value, I get weird characters.
我尝试使用bin2hex
,然后尝试将十六进制转换为字符串,但是没有运气.
I've tried using bin2hex
and then tried to convert the hex to string but with no luck.
我知道MySQL的AsText()
,但是我想用PHP做到.
I'm aware of MySQL's AsText()
, but I would like to do it in PHP.
推荐答案
最后,我已经开始工作了!!
Finally I've got this working!!!
我必须使用解压缩才能从MySQL中提取二进制数据
I had to use unpack in order to extract the binary data from MySQL
$point_value = $data_from_db["point_field"];
$coordinates = unpack('x/x/x/x/corder/Ltype/dlat/dlon', $point_value);
echo $coordinates['lat'];
echo $coordinates['lon'];
此处是一个tutotial帮助我解决了这个问题
Here is a tutotial that helped me with this issue
这篇关于将MySQL的POINT转换为PHP中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!