<?php
/**
* Documents the file following
* @package googlemapsForWP
* @subpackage geocodes
* @author webcat
*/
//#################################################################
if (preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
die('You are not allowed to call this page directly.');
}
//#################################################################
if (!class_exists('gmfwpGeoCodes')) {
/**
* googlemapsForWP maps
* The class provides access to
*/
class gmfwpGeoCodes {
protected static $LIMIT = 2500;
protected static $GEOAPI = "http://maps.googleapis.com/maps/api/geocode/";
protected $error;
protected $resultsArr;
function __construct() {
$this->resultsArr = array();
try {
if (!file_exists(googlemapsForWP::pluginDir() . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'googlemapsForWPvalidation.php')) {
throw new Exception();
} else {
require_once(googlemapsForWP::pluginDir() . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'googlemapsForWPvalidation.php');
$this->error = new gmfwpLocationCheck();
}
} catch (Exception $e) {
die("error");
}
}
function getCodes($lola) {
$return = "error";
if ($this->error->checkAddress($lola)) {
$address = gmfwpGeoCodes::$GEOAPI . "json?address=" . $lola."&sensor=false";
try {
$ch = curl_init();
if ($ch) {
curl_setopt($ch, CURLOPT_URL, $address);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1) ;
if($this->getJSON(curl_exec($ch))){
curl_close($ch);
$return=$this->resultsArr['long'].";".$this->resultsArr['lat'];
}
return $return;
}
} catch (Exception $e) {
return $return;
}
} else {
return $return;
}
}
/**
* @todo
* @param <type> $input
*/
private function getXML($input) { }
/**
* SETS THE RESULTaRR TO HOLD PARSED JSON
* @todo parse whole file and provide getters for params to get limits for flags
* @param <type> $input
*/
private function getJSON($input) {
$res=json_decode($input,true);
if($res['status']=='OK'){
$this->resultsArr['lat']=$res['results'][0]['geometry']['location']['lat'];
$this->resultsArr['long']=$res['results'][0]['geometry']['location']['lng'];
return true;
}else{
return false;
}
}
}
}