我想将地址转换成latitude.here是我的代码。 但它给错了纬度。如果我手动将地址放在$最后的地方,它会给出正确的纬度。但是我无法对其进行硬编码,无论源文本框中有什么来源,我都必须找出地址纬度。什么是错误?php地址转为经纬度
<?php
$source=$_POST['textfield11'];
$dest=$_POST['textfield12'];
$time=$_POST['textfield13'];
$only = str_replace(',', '+', $source);
$final = str_replace(' ', '+', $only);
$url='http://maps.googleapis.com/maps/api/geocode/json?address=$final&sensor=false';
$source1 = file_get_contents($url);
$obj = json_decode($source1);
$LATITUDE = $obj->results[0]->geometry->location->lat;
echo $LATITUDE;
?>
也许你已经尝试了一些什么信息? http://blog.codinghorror.com/rubber-duck-problem-solving/ – Smandoli
我的猜测是你给'$ final'的价值正在被搞砸。你是否在geocode调用之前尝试了var_dump($ final)来查看'$ final'实际上是什么? – Rottingham
如果$ final包含不安全的URL字符,那可能会将其搞乱(除了将空格改为加号)。可以试试$ final = urlencode(仅限$); – SyntaxLAMP