我正在努力将Google的Places API集成到网络应用中.我已经能够成功创建代码以允许用户使用API搜索地点并在应用程序中显示结果,这样很酷.
我无法弄清楚的是如何让应用程序的用户添加新的地方.谷歌说的东西是可行的.他们在这里有一些文件 -
https://code.google.com/apis/maps/documentation/places/#adding_a_place
但是没有示例代码,我在编写PHP代码以实现add调用时遇到了一些困难.
这是我到目前为止提出的代码.我在这里用{your key}替换了我的实际API密钥.
我一直收到错误的帖子错误 -
那是一个错误.您的客户发出了格式错误或非法的请求.我们知道的就这些.
<?php
function ProcessCurl($URL, $fieldString){ //Initiate Curl request and send back the result
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADERS, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('json'=>json_encode($fieldString)));
$resulta = curl_exec ($ch);
if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
}
echo $resulta;
}
$jsonpost = '{
"location": {
"lat": -33.8669710,
"lng": 151.1958750
},
"accuracy": 50,
"name": "Daves Test!",
"types": ["shoe_store"],
"language": …
Run Code Online (Sandbox Code Playgroud)