Php 试图获取非对象地理位置google API的属性

Php 试图获取非对象地理位置google API的属性,php,google-maps,google-maps-api-3,latitude-longitude,google-geolocation,Php,Google Maps,Google Maps Api 3,Latitude Longitude,Google Geolocation,我正在通过地理定位API从谷歌地图中获取纬度和经度。我尝试过很多次,但始终显示出以下错误: 试图在第16行的C:\wamp64\www\index3.php中获取非对象的属性 问题是我无法从$url获取信息,因此无法获取纬度和经度 我改变了我的代码,现在它是,但仍然没有工作 <php $address = urlencode('BTM 2nd Stage,Bengaluru,Karnataka,560076'); $url = "https://maps.googleapis.com/m

我正在通过地理定位API从谷歌地图中获取纬度和经度。我尝试过很多次,但始终显示出以下错误:

试图在第16行的C:\wamp64\www\index3.php中获取非对象的属性

问题是我无法从
$url
获取信息,因此无法获取纬度和经度

我改变了我的代码,现在它是,但仍然没有工作

<php

$address = urlencode('BTM 2nd Stage,Bengaluru,Karnataka,560076');
$url = "https://maps.googleapis.com/maps/api/geocode/json?address=$address&key=*************************************";


$json = file_get_contents($url); // I tried with the @ symbol and without it

$data=json_decode($json);

echo ($data->results[0]->geometry->location->lat);

?>
结果[0]->几何->位置->横向;
?>
我还用了这个:

<php
$address = 'BTM 2nd Stage,Bengaluru,Karnataka,560076';
$encode = urlencode($address);
$key = "insert key here";
$url = "https://maps.googleapis.com/maps/api/geocode/json?address={$encode}&key={$key}";

$json = file_get_contents($url); // I tried with the @ symbol and without it
$data = json_decode($json);

echo "Latitud".($data->results[0]->geometry->location->lat);

?>
结果[0]->几何->位置->横向;
?>
如果没有@符号,我有这个错误行

警告:出于安全原因,第8行的[…][…]中已禁用文件\u get\u contents()


更改http
在您的请求url中使用https。

作为Abrucius,您必须使用https,否则google将拒绝该请求。您还必须对地址进行编码,否则将出现“错误请求”错误

<?php
$address = 'BTM 2nd Stage,Bengaluru,Karnataka,560076';
$encode = urlencode($address);
$key = "insert key here";
$url = "https://maps.googleapis.com/maps/api/geocode/json?address={$encode}&key={$key}";

$json = file_get_contents($url);
$data = json_decode($json);

echo ($data->results[0]->geometry->location->lat);    
替换以下代码

    $address = 'BTM 2nd Stage,Bengaluru,Karnataka,560076';
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=$address&key=AIzaSyDjWI3J9CNlANoB5PXNKq3nz1ZbYeOrNGE";


您在url中提供了
http
,它应该是
https
。尝试下面的代码将帮助您。您必须使用
urlencode()
,因为api不允许地址中有空格,所以您必须进行编码

$address = 'BTM 2nd Stage,Bengaluru,Karnataka,560076';
$address = urlencode($address);

$url = "https://maps.google.com/maps/api/geocode/json?address={$address}&key=***************************";

$resp_json = file_get_contents($url);

$resp = json_decode($resp_json, true);
echo "<pre>";print_r($resp["results"][0]['geometry']['location']['lat']);
$address='BTM第二阶段,卡纳塔克邦班加鲁,560076';
$address=urlencode($address);
$url=”https://maps.google.com/maps/api/geocode/json?address={$address}&key=*******************************”;
$resp_json=file_get_contents($url);
$resp=json_decode($resp_json,true);
回声“;打印($resp[“results”][0]['geometry']['location']['lat']);

试试这个代码肯定会有用的

WillParky93的答案对我来说似乎很有用。可能尝试以下链接以允许https包装器:


…或者发布您遇到的错误,以便我们可以帮助您解决问题

我刚刚解决了这个问题,我遇到这个错误是因为代理配置。我正在测试一个带有代理配置的网络。所以,代理不允许我连接谷歌数据库。然后我尝试连接到一个不同的网络,它工作得非常好。谢谢你们的帮助

可能的副本(没有第16行;)你能显示
$data
中的内容吗?我很确定你不应该向所有人显示你的应用程序密钥。是的,我编辑了它,但它仍然显示相同的错误。。。在最后一行中,下次我可以建议您从OP中如此明显的错误开始吗?该错误特别指出该功能已在服务器级别上被禁用。尝试使用
curl
但是如果
file\u get\u contents
被禁用,那么curl很可能也被禁用了。找一个不同的主机..做了,但不起作用。甚至我从
file\u get\u contents
指令中删除了“at”符号,并向我显示:
file\u get\u contents()已出于安全原因被禁用
警告:file\u get\u contents()已出于安全原因在[…][…]中被禁用
您收到了错误。然后您必须联系服务器提供商以启用该功能
$address = 'BTM 2nd Stage,Bengaluru,Karnataka,560076';
$address = urlencode($address);

$url = "https://maps.google.com/maps/api/geocode/json?address={$address}&key=***************************";

$resp_json = file_get_contents($url);

$resp = json_decode($resp_json, true);
echo "<pre>";print_r($resp["results"][0]['geometry']['location']['lat']);