本文整理汇总了PHP中app\City::whereName方法的典型用法代码示例。如果您正苦于以下问题:PHP City::whereName方法的具体用法?PHP City::whereName怎么用?PHP City::whereName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\City
的用法示例。
在下文中一共展示了City::whereName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getGoogleCoords
public function getGoogleCoords($city)
{
$city_db = City::whereName($city)->first();
$google_api = "AIzaSyB-7u1CvRIkmsjcHVVQgilPj6doeIh93oA";
$baseURL = "http://maps.googleapis.com/maps/api/geocode/json?address=";
$format = "&key=" . $google_api;
$query = "philippines,+" . $city_db->province->name . ",+" . $city_db->name;
$callURL = $baseURL . $query . $format;
$session = curl_init($callURL);
curl_setopt($session, CURLOPT_URL, $callURL);
curl_setopt($session, CURLOPT_BINARYTRANSFER, true);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($session);
curl_close($session);
// Decode JSON response:
$coords = json_decode($json, true);
dd($coords);
$data['lat'] = $coords["results"][0]["geometry"]["location"]["lat"];
$data['long'] = $coords["results"][0]["geometry"]["location"]["long"];
$data['postcode'] = $coords["results"][0]["address_components"];
$data['city_id'] = $city_db->id;
dd($data);
return $data;
}