Thanks for your reply but I get the following error
Here is the code to line 7:
$curl = new Curl; // creates instance of that class
And this is my full code:
<?php
App::import('Vendor','curl',array('file'=>'curl/curl.php'));
class AssessorsController extends AppController {
var $name = 'Assessors';
$curl = new Curl; // creates instance of that class
var $helpers = array('Html', 'Form');
function index() {
$this->Assessor->recursive = 0;
$this->set('assessors', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Assessor', true));
$this->redirect(array('action' => 'index'));
}
$this->set('assessor', $this->Assessor->read(null, $id));
}
//ABQIAAAAKTQxwK9voUwewo30TXUphhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQPqIzmFOVR0ei9267lDn2Th4XtTw
/**
function add() {
if (!empty($this->data)) {
$this->Assessor->geocode($this->data['Assessor']['zip']);
$this->Assessor->create();
if ($this->Assessor->save($this->data)) {
$this->Session->setFlash(__('The Assessor has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The Assessor could not be saved. Please, try again.', true));
}
}
}
*/
function add() {
if (!empty($this->data)) {
$this->Assessor->geocode($this->data['Assessor']['zip']);
$latlong = $this->get_lat_long($this->data['Assessor']['zip'])
print_r($latlong);
}
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Assessor', true));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->Assessor->save($this->data)) {
$this->Session->setFlash(__('The Assessor has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The Assessor could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Assessor->read(null, $id);
}
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for Assessor', true));
$this->redirect(array('action' => 'index'));
}
if ($this->Assessor->del($id)) {
$this->Session->setFlash(__('Assessor deleted', true));
$this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('The Assessor could not be deleted. Please, try again.', true));
$this->redirect(array('action' => 'index'));
}
function admin_index() {
$this->Assessor->recursive = 0;
$this->set('assessors', $this->paginate());
}
function admin_view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Assessor', true));
$this->redirect(array('action' => 'index'));
}
$this->set('assessor', $this->Assessor->read(null, $id));
}
function admin_add() {
if (!empty($this->data)) {
$this->Assessor->create();
if ($this->Assessor->save($this->data)) {
$this->Session->setFlash(__('The Assessor has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The Assessor could not be saved. Please, try again.', true));
}
}
}
function admin_edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Assessor', true));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->Assessor->save($this->data)) {
$this->Session->setFlash(__('The Assessor has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The Assessor could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Assessor->read(null, $id);
}
}
function admin_delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for Assessor', true));
$this->redirect(array('action' => 'index'));
}
if ($this->Assessor->del($id)) {
$this->Session->setFlash(__('Assessor deleted', true));
$this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('The Assessor could not be deleted. Please, try again.', true));
$this->redirect(array('action' => 'index'));
}
#Private Functions
/**
* Returns a lat / long of a given postcode
*
*/
function get_lat_long($postcode,$domain=null) {
if(!$domain) {
$domain = "co.uk";
}
$url = "http://maps.google." . $domain . "/maps/geo?q=" . urlencode($postcode) . "&output=json&key=ABQIAAAAKTQxwK9voUwewo30TXUphhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQPqIzmFOVR0ei9267lDn2Th4XtTw";
// $json = $this->curl->get_page(array("url"=>$url));
$curl->get_page(array("url"=>$url)); // from your code
$store_data = json_decode(str_replace(""","\"",htmlentities($json))); //Take care of accents
$lng = $store_data->Placemark[0]->Point->coordinates[0];
$lat = $store_data->Placemark[0]->Point->coordinates[1];
//Return
if($lng && $lat) {
return array('lat'=>$lat,
'lng'=>$lng
);
} else {
return false;
}
}
}
?>
Do let me know if I have done anything silly!
Thanks,
Blue...