Visualizzazione dei risultati da 1 a 3 su 3

Discussione: problema con geocoder

  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2013
    Messaggi
    83

    problema con geocoder

    Salve ho questo codice:

    <?php
    // Geocode addresses using the Yahoo Geocoding API
    // Turning on track_errors stores the latest PHP error in $php_errormsg.
    // This allows for more elegant display of the error messages without having to
    // code a php error handler, which would be overkill for such a simple script.
    ini_set('track_errors',TRUE);
    mysql_connect('localhost', 'root', 'password');
    mysql_select_db('sintesys1');
    // Variabili di configurazione da utilizzare successivamente
    $geocode_url = 'http://maps.google.com/maps/api/geocode/json?address=albert%20square&sensor=false';
    // Inserisci il tuo appid personalizzato qui
    $appid ='sample_appid';
    // Ottenere gli indirizzi che non sono stati geocodificati
    $address_result = mysql_query("SELECT distinct report_event.luogo, report_event.id
    FROM report_event
    WHERE report_event.luogo !='' AND report_event.id !=''");
    // Se la query MySQL ha restituito alcuna riga , loop attraverso di loro
    if(mysql_num_rows($address_result) > 0){
    while ($row = mysql_fetch_assoc($address_result)){
    // appid è richiesto per ogni chiamata al geocode API yahoo
    $row['appid'] = $appid;
    // output can be either xml or php
    $row['output'] = 'php';
    // Store the row id for updating the database and remove from $row array
    $id = $row['id'];
    unset($row['id']);
    // Build the query string for sending the request to yahoo
    $query_string = http_build_query($row, '', '&');
    // Get latitute / longitude
    $response = @file_get_contents($geocode_url.'?'.$query_string) ;
    if($response == false){
    // If the call to the yahoo api failed, display an error message
    echo 'ERROR: '.$php_errormsg;
    }
    else{
    // Get the results of the api call and update the database records
    $response_array = unserialize($response);
    $lat = mysql_real_escape_string($response_array['ResultSet']['Result']['lat']);
    $lon = mysql_real_escape_string($response_array['ResultSet']['Result']['lon']);
    $update_result = mysql_query("UPDATE report_event SET lat = '$lat', lon = $lon WHERE report_event.id = $id");
    // For each record, let the user know if the update was successful. If not, display the mysql error message generated.
    if($update_result == TRUE){
    echo "Added lattitude and longitude for {$row['luogo']}.";
    }
    else{
    echo "Unable to add latitude and longitude for {$row['luogo']}
    MySQL Error: ".mysql_error();
    }
    }
    echo '<br />';
    }
    }
    else{
    echo "Nothing to do.";
    }
    ?>


    mi ritorna il seguente errore:

    Notice: unserialize(): Error at offset 0 of 167 bytes in C:\xampp\htdocs\r\k.php on line 37
    Unable to add latitude and longitude for Serbia MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE report_event.id = 5467' at line 1


    Sbaglio a scrivere qualcosa?

  2. #2
    Utente di HTML.it L'avatar di Fichico
    Registrato dal
    Nov 2002
    residenza
    Bologna
    Messaggi
    581
    a parte che non hai indicato la riga dell'errore ... ma guardando il codice direi che l'errore è qua:
    Codice PHP:
    $update_result mysql_query("UPDATE report_event SET lat = '$lat', lon = $lon WHERE report_event.id = $id"); 
    dovrebbe esser:
    Codice PHP:
    $update_result mysql_query("UPDATE report_event SET lat = '$lat', lon = '$lon' WHERE report_event.id = $id"); 

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2013
    Messaggi
    83
    quell'errore che mi hai suggerito tu lo avevo già visto;

    cmq la riga 37 è questa: $response_array = unserialize($response);

    ed ho il seguente errore

    Notice: unserialize(): Error at offset 0 of 167 bytes in C:\xampp\htdocs\r\k.php on line 37
    Unable to add latitude and longitude for Cisgiordania MySQL Error: Data truncated for column 'lat' at row 1
    Ultima modifica di serino84; 23-10-2013 a 09:37

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.