Convert MySQL's POINT to text in PHP


Using PHP, how can I convert a value inPOINT datatype to a string likePOINT (-34.601020 -58.371020) (an ouput in WKT or GeoJSON is preferable)

If I echo the raw value, I get weird characters.

I've tried usingbin2hex and then tried to convert the hex to string but with no luck.

I'm aware of MySQL'sAsText(), but I would like to do it in PHP.




Finally I've got this working!!!

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'];

Here is a tutotial that helped me with this issue

People are also looking for solutions to the problem: apache - same file with .php and without .php without any mod_rewrite RewriteRule


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.