2012-12-03 34 views
2

请我做了这个代码来获取经度和纬度得到充分的经度和纬度:PHP如何使用谷歌API

$addresss = "France+mande-lieu-la-napol"; 
$region = "Alpes-Maritimes"; 
$urll  = "http://maps.google.com/maps/api/geocode/json?address=$addresss&sensor=false&region=$region"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $urll); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_PROXYPORT, 3128); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
$response = curl_exec($ch); 
curl_close($ch); 
$response_a = json_decode($response); 

var_dump ($response_a->results[0]->geometry->location->lat); 

var_dump ($response_a->results[0]->geometry->location->lng); 

此代码给我的结果:

float(43.546232) float(6.938309) 

但实际上它必须给我

float(43.546232) float(6.938309000000004) 

请问我该怎么做才能获得全部的经度?

+0

为什么?它返回的当前值有什么问题? – thescientist

回答

1

您应该使用json_decode($json, true, 512, JSON_BIGINT_AS_STRING),以便lat和long将作为字符串而不是float返回。