我使用Google Maps Geolocation API来获取用户的地址和lng坐标,我阅读了Google Maps Geolocation API'文档,我将此代码用于我的网站
`<?php
$requestbody=array("considerIp"=>"true");
$ch = curl_init();
curl_setopt($ch,
CURLOPT_URL,"https://www.googleapis.com/geolocation/v1/geolocate?
key=AIzaSyDsJyehD0QRujG5********");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$requestbody);
$result = curl_exec ($ch);
curl_close ($ch);
echo $result;
?>`
我总是收到此错误
{“error”:{“errors”:[{“domain”:“global”,“reason”:“badContent”,“message”:“不支持的内容类型:multipart / form-data; boundary = - ----------------------- 3fbf377f9ad74da3“}],”code“:400,”message“:”不支持的内容类型:multipart / form-data; boundary = ------------------------ 3fbf377f9ad74da3“}}
在docs中,Google表示thinkIp = true意味着当wifi站点或手机连接不可用时我将收到IP位置,但我不知道为什么会出现此错误
https://developers.google.com/maps/documentation/geolocation/intro