Visualizzazione dei risultati da 1 a 3 su 3

Discussione: Geolocalizzazione

  1. #1

    Geolocalizzazione

    Ciao a tutti
    Ho trovato questo script in rete per la geolocalizzazione:

    Codice PHP:
    function geocode($address){
    // url encode per l'indirizzo
    $address urlencode($address);
    // google map geocode api url
    $url "https://maps.googleapis.com/maps/api/geocode/json?address={$address}&key=xxxxxxxxxxxxxxxxxxx";
    // Acquisisce i risultati json
    $resp_json file_get_contents($url);
    // decodifica json
    $resp json_decode($resp_jsontrue);
    // Restituiscee 'OK', se c'è un indirizzo geocodificato
    if($resp['status']=='OK'){
    // Raccoglie i dati fondamentali per la visualizzazione della mappa
    $lati = isset($resp['results'][0]['geometry']['location']['lat']) ? $resp['results'][0]['geometry']['location']['lat'] : "";
    $longi = isset($resp['results'][0]['geometry']['location']['lng']) ? $resp['results'][0]['geometry']['location']['lng'] : "";
    $formatted_address = isset($resp['results'][0]['formatted_address']) ? $resp['results'][0]['formatted_address'] : "";
    // Verifica della completezza dei dati
    if($lati && $longi && $formatted_address) {
    // Inserisce i dati in un Array
    $data_arr = array();
    array_push($data_arr$lati$longi$formatted_address);
    return 
    $data_arr;
    } else {
    return 
    false;
    }
    } else {
    echo 
    "<strong>ERRORE: {$resp['status']}</strong>";return false;   
    }
    }

    $data_geo geocode("Roma RM via Cristoforo Colombo 10");
    echo 
    "Dati deolocalizzazione: ".$data_geo[0]; 
    Ma mi da questo errore: ERRORE: REQUEST_DENIED
    Ultima modifica di techno; 21-04-2021 a 12:05

  2. #2
    Ok ho risolto dovevo abilitare le api ma mi sta succendendo una cosa strana

    codice:
    $address = urlencode("Roma Italia");
    
    $api='https://maps.googleapis.com/maps/api/geocode/json?address={$address}&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    
    $result = file_get_contents($api);
    $result = json_decode($result, true);
    print_r($result);
    
    echo "<br>latidutine: ".$result['results'][0]['geometry']['location']['lat'];
    echo "<br>longitudine: ".$result['results'][0]['geometry']['location']['lng'];
    
    Il problema e che mi da sempre un indirizzo americaano di Houston

    ( [results] => Array ( [0] => Array ( [address_components] => Array ( [0] => Array ( [long_name] => 3333 [short_name] => 3333 [types] => Array ( [0] => street_number ) ) [1] => Array ( [long_name] => Raleigh Street [short_name] => Raleigh St [types] => Array ( [0] => route ) ) [2] => Array ( [long_name] => South Side [short_name] => South Side [types] => Array ( [0] => neighborhood [1] => political ) ) [3] => Array ( [long_name] => Houston [short_name] => Houston [types] => Array ( [0] => locality [1] => political ) ) [4] => Array ( [long_name] => Harris County [short_name] => Harris County [types] => Array ( [0] => administrative_area_level_2 [1] => political ) ) [5] => Array ( [long_name] => Texas [short_name] => TX [types] => Array ( [0] => administrative_area_level_1 [1] => political ) ) [6] => Array ( [long_name] => United States [short_name] => US [types] => Array ( [0] => country [1] => political ) ) [7] => Array ( [long_name] => 77021 [short_name] => 77021 [types] => Array ( [0] => postal_code ) ) [8] => Array ( [long_name] => 2458 [short_name] => 2458 [types] => Array ( [0] => postal_code_suffix ) ) ) [formatted_address] => 3333 Raleigh St, Houston, TX 77021, USA [geometry] => Array ( [location] => Array ( [lat] => 29.7020977 [lng] => -95.3732787 ) [location_type] => ROOFTOP [viewport] => Array ( [northeast] => Array ( [lat] => 29.703446680291 [lng] => -95.371929719709 ) [southwest] => Array ( [lat] => 29.700748719708 [lng] => -95.374627680292 ) ) ) [place_id] => ChIJkSmaoeq_QIYR9icUUkXm9Ck [plus_code] => Array ( [compound_code] => PJ2G+RM South Side, Houston, TX, USA [global_code] => 76X6PJ2G+RM ) [types] => Array ( [0] => bar [1] => establishment [2] => food [3] => night_club [4] => point_of_interest [5] => restaurant ) ) ) [status] => OK )

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2011
    Messaggi
    189
    Ad esempio, un codice geografico per "Rome" restituisce questo risultato, poiché il dominio predefinito per l'API di geocodifica è impostato sugli Stati Uniti.
    Cambia in address=Rome&region=it riferimento https://developers.google.com/maps/d...oding/overview

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 © 2024 vBulletin Solutions, Inc. All rights reserved.