/** * Get the latitude/longitude for a given address. * * Google Server-Side API geocoding is documented here: * https://developers.google.com/maps/documentation/geocoding/index * * Required Google Geocoding API Params: * address * sensor=true|false * * Optional Google Geocoding API Params: * bounds * language * region * components * * @param string $address the address to geocode * @return string $response the JSON response string */ function get_LatLong($address) { if (!isset($this->geocodeLanguage)) { $this->geocodeLanguage = '&language=' . $this->slplus->helper->getData('map_language', 'get_item', null, 'en'); } if (!isset($this->geocodeURL)) { $this->geocodeURL = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false' . $this->geocodeLanguage . '&address='; } // Set comType if not already determined. // if (!isset($this->comType)) { if (isset($this->slplus->http_handler)) { $this->comType = 'http_handler'; } elseif (extension_loaded("curl") && function_exists("curl_init")) { $this->comType = 'curl'; } else { $this->comType = 'file_get_contents'; } } $fullURL = $this->geocodeURL . urlencode($address); // Go fetch the data from the remote server. // switch ($this->comType) { case 'http_handler': $result = $this->slplus->http_handler->request($fullURL, array('timeout' => 3)); if ($this->slplus->http_result_is_ok($result)) { $raw_json = $result['body']; } else { $raw_json = null; } break; case 'curl': $cURL = curl_init(); curl_setopt($cURL, CURLOPT_URL, $fullURL); curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1); $raw_json = curl_exec($cURL); curl_close($cURL); break; case 'file_get_contents': $raw_json = file_get_contents($fullURL); break; default: $raw_json = null; return; } return $raw_json; }