将MySQL的POINT转换为PHP中的文本 [英] Convert MySQL's POINT to text in PHP

查看:138
本文介绍了将MySQL的POINT转换为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆