← Desenvolvimento

Dúvida Google API

Lida 1817 vezes

Offline

Pedro Moreira 
Membro
Mensagens 93 Gostos 0
Troféus totais: 16
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 3 Level 2 Level 1 50 Posts 10 Posts First Post Karma

Tenho Esta programaçao:

<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of gMaps
 *
 * @author Only Informatica
 */
class gMaps {
    //put your code here
    // Host do GoogleMaps
    private $mapsHost = 'maps.google.com';
    // Sua Google Maps API Key
    public $mapsKey = '';

    function __construct($key = null) {
        if (!is_null($key)) {
            $this->mapsKey = $key;
        }
    }


 function carregaUrl($url) {
        if (function_exists('curl_init')) {
            $cURL = curl_init($url);
            curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($cURL, CURLOPT_FOLLOWLOCATION, true);
            $resultado = curl_exec($cURL);
            curl_close($cURL);
        } else {
            $resultado = file_get_contents($url);
        }
        if (!$resultado) {
            return false;
            //trigger_error('Não foi possível carregar o endereço: <strong>' . $url . '</strong>');
        } else {
            return $resultado;
        }
    }
 

    function geoLocal($endereco) {
        $url = 'http://'. $this->mapsHost .'/maps/geo?output=csv&key='. $this->mapsKey .'&q='. urlencode($endereco);
        $dados = $this->carregaUrl($url);
        list($status, $zoom, $latitude, $longitude) = explode(',', $dados);
        if ($status != 200) {
            return false;
            //trigger_error('Não foi possível carregar o endereço <strong>"'.$endereco.'"</strong>, código de resposta: ' . $status);
        }
        return array('lat' => $latitude, 'lon' => $longitude, 'zoom' => $zoom, 'endereco' => $endereco);
    }

}
?>


E ao entrar no site dame este erro :  Este website precisa de uma chave diferente para a API do Google Maps. Uma nova chave pode ser gerada em http://code.google.com/apis/maps/documentation/javascript/v2/introduction.html#Obtaining_Key.

E depois ao entrar na página da localização, surge este:

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/site/public_html/classes/gMaps.class.php on line 30


Alguem me podera ajudar ?
Offline

Rob 
Membro
Mensagens 132 Gostos 0
Troféus totais: 22
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 4 Level 3 Level 2 Level 1 100 Posts 50 Posts 10 Posts

Não estás a conseguir fazer o request HTTP.

O PHP tem activo no INI a variavel "safe_mode", deverarás ter que desactivar esta flag, não sei quais são as implicações de segurança disto.

Já agora certifica através do phpinfo() que tens a extensão/modulo CURL instalado.