所以我有这条路线
Route::get('/locations/{lat}/{lng}', ['as'=>'locations.find', 'uses'=> 'LocationsController@find']);
这将我带到控制器
public function Find($lat,$lng)
{
$URLToCall = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=".$lat.",".$lng."&key=".self::$apiKey;
// $URLToCall = "https://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($placeName)."&key=".self::$apiKey;
$result = json_decode(file_get_contents($URLToCall),true);
if($result['status'] == "OK") {
$URLToCall = "https://maps.googleapis.com/maps/api/place/details/json?placeid=".$result['results'][0]['place_id']."&key=".self::$apiKey;
$result = json_decode(file_get_contents($URLToCall),true);
// echo $URLToCall;
// print_r($result);
$googlePlaceData = $result['result'];
$place_id = $googlePlaceData['place_id'];
$address = $googlePlaceData['name'];
$name = $googlePlaceData['name'];
$lat = $googlePlaceData['geometry']['location']['lat'];
$lng = $googlePlaceData['geometry']['location']['lng'];
$formatted_address = $googlePlaceData['formatted_address'];
// echo $formatted_address;
// dd($result['result']);
$location = LocationRepository::get($place_id, $address);
echo $location;
// return response()->json(json_decode($location));
} else {
echo "Could not Find Data";
}
}
}
现在,当我添加新位置时,我得到了 请求方法:GET 状态代码:500内部服务器错误
但是当我刷新相同的Url时,我会按照我想要的方式获取数据。 问题应该是我返回数据的方式。但是我无法弄清楚我该怎么做才能搞定它。我添加一个新的lat,lng,我没有保存在我的位置数据库中。我收到这个错误。 任何帮助将不胜感激。感谢