Sometimes i enter an address and i get this triggered:
$json['error'] = $this->lang->line('alert_invalid_search_query'); // display error: enter postcode
But if i click the search button again without changing anything on the textbox the text works fine (i have google autocomplete on the form)
Is there any way that i can bypass this check and when its tiggered it will auto-retry without the user noticing ?
[php]public function getLatLng($search_query = FALSE) { // method to perform regular expression match on postcode string and return latitude and longitude
if (empty($search_query)) {
return "NO_SEARCH_QUERY";
}
$local_info = empty($local_info) ? $this->CI->session->userdata('local_info') : $local_info;
if (isset($local_info['geocode']['search_query']) AND $local_info['geocode']['search_query'] === $search_query) {
return $local_info['geocode'];
}
$temp_query = $search_query;
if (is_string($temp_query)) {
$postcode = strtoupper(str_replace(' ', '', $temp_query)); // strip spaces from postcode string and convert to uppercase
if (preg_match("/^[A-Z]{1,2}[0-9]{2,3}[A-Z]{2}$/", $postcode) OR
preg_match("/^[A-Z]{1,2}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{2}$/", $postcode) OR
preg_match("/^GIR0[A-Z]{2}$/", $postcode)) {
$temp_query = $postcode;
} else {
$temp_query = explode(' ', $temp_query);
}
}
$temp_query = (is_array($temp_query)) ? implode(', ', $temp_query) : $temp_query;
$url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($temp_query) .'&sensor=false'; //encode $postcode string and construct the url query
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $this->CI->agent->agent_string());
$geocode_data = curl_exec($ch);
curl_close($ch);
$output = json_decode($geocode_data); // decode the geocode data
if ($output) {
if ($output->status === 'OK') { // create variable for geocode data status
$this->geocode = array(
'search_query' => $search_query,
'lat' => $output->results[0]->geometry->location->lat,
'lng' => $output->results[0]->geometry->location->lng
);
return $this->geocode;
}
return "INVALID_SEARCH_QUERY";
}
return "FAILED";
}[/php]
Thats the function that returns that error, im not a PHP EXPERT but i cannot seem to understand why this line is there and if its correct.