I have the following variable with some coordinates from google maps:
$coordinates = '(22.2819939, 114.15444100000002)';
So to separate them I did the following:
$coor = explode(',',str_replace(array('(',')'),'',$coordinates));
Now I need to send this coordinates to an API in the following format:
$message = array("location"=>array($coor[1],$coor[0]));
I must send this in json so I encode the array but I am getting the coordinates as strings and not as number:
$toSend = json_encode($message);
result-> {"location":["114.15444100000002","22.2819939"]}
How can I avoid json to take the coordinates as string and take them as number instead?
I need this result:
{"location":[114.15444100000002,22.2819939]}
$message = array("location"=>array((float)$coor[1], (float)$coor[0]));?(double) "114.15444100000002"114.15444100000002looks incorrect. Google Maps provides 6 decimal points of precision, afaik. I think you hit a floating point precision issue before it got stored.114.154441is the number you want, pretty sure.