$job = $this->JobPostInfo->find('first', array(
'conditions' => array('JobPostInfo.id' => 3),
'recursive' => -1,
'fields' => array('JobPostInfo.user_id'),
));
$employerLocationInfo = $this->EmployerContactDetail->find('first', array(
'conditions' => array('EmployerContactDetail.user_id' => $job['JobPostInfo']['user_id']),
'recursive' => -1,
'fields' => array('EmployerContactDetail.address'),
));
$split_address = preg_split('/[\ \n\,]+/', $employerLocationInfo['EmployerContactDetail']['address']);
$str = '';
foreach($split_address as $value){
$value = str_replace(' ', '', $value);
$str .= '+'.$value;
}
$str= trim($str,'+');
$ch = curl_init();
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
);
curl_setopt($ch, CURLOPT_URL, "https://maps.googleapis.com/maps/api/geocode/json?address=".$str."&sensor=true&key=AIzaSyBnPOKe9dLW_8PfE78ubqrJ4_SQDyOgPsg");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$json = curl_exec($ch);
curl_close ($ch);
// $fullurl = "https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true&key=AIzaSyBnPOKe9dLW_8PfE78ubqrJ4_SQDyOgPsg";
// $string = file_get_contents($fullurl); // get json content
// $json = json_decode($string, true); //json decoder
$response = json_decode($json, true);
$mapsLatLongData = $response['results'][0]['geometry']['location'];
$this->set(compact('mapsLatLongData'));