相关疑难解决方法(0)

使用php,API自动获取经度和纬度

在我的一个php应用程序中,我必须从地址中找出该地点的纬度和经度.

我试过这段代码:

$json = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false&region=$region");
$json = json_decode($json);

$lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
Run Code Online (Sandbox Code Playgroud)

但它显示以下错误:

警告:file_get_contents(http://maps.google.com/maps/api/geocode/json?address=technopark,Trivandrun,kerala,India&sensor = false®ion = IND)[function.file-get-contents]:无法打开流:HTTP请求失败!第4行的D:\ Projects\lon.php中的HTTP/1.0 400错误请求

请帮我解决这个问题.

php google-maps-api-3

24
推荐指数
3
解决办法
11万
查看次数

标签 统计

google-maps-api-3 ×1

php ×1