0

I have a one little question about this error, i don't know where i do wrong, getting error message.

Have somebody can help me to see the problem? Thank you very much!

public function getLatLong($address, $regionName = '') {
    $error_msg = __('There is issue with this address. Unable to locate locate store on Google Map.');
    if (!empty($address)) {
        $address = str_replace(" ", "+", $address);
        $address =  preg_replace('~[\r\n\t]+~', '', $address);
        $url = $this->getStoreConfig(self::GEOCODE_API_URL_CONFIG_PATH);
        $apiKey = $this->getStoreConfig(self::API_KEY);
        if(empty($apiKey)) {
            $error_msg = __('Please set Gmaps Api Key in Map settings from store configuration.');
        }
        $url = $url . $address . "&sensor=false";
        if ($regionName)
            $url .= "&region=" . $regionName;
        $url = $url . '&key=' . $apiKey;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $response = curl_exec($ch);
        if (curl_error($ch)) {
            $error_msg = curl_error($ch);
        }
        curl_close($ch);
        $jsonArray = json_decode($response, 1);
        if (isset($jsonArray) && !empty($jsonArray['results'])) {
            $data['latitude'] = $jsonArray['results'][0]['geometry']['location']['lat'];
            $data['longitude'] = $jsonArray['results'][0]['geometry']['location']['lng'];
        } else {
            $data['error'] =$error_msg;
        }
        return $data;
    }
    return false;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.