Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2012
    Messaggi
    11

    problema con getCurrentPosition e passaggio variabili a file php

    Salve, sono giorni che esco pazzo!!!

    Spero intanto che sia argomento di questo forum perchè poteva andare anche in HTML5 e PHP.

    Devo leggere con il PHP due variabili che vengono create con un javascrip.
    Ho letto comunque per fare questo l'unico metodo è quello di passare con metodo POST le variabili dal file che contiene il javascript al file PHP che le legge.

    il mio file è fatto cosi....

    "get_gps.html"

    <!DOCTYPE html>
    <html lang="en-US">
    <head>
    <title>SPACE-O :: Get Visitor Location using HTML5</title>


    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>


    <script>


    $(document).ready(function(){
    if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showLocat ion);
    } else {
    $('#location').html('Geolocation is not supported by this browser.');
    }
    });


    function showLocation(position) {

    var latitude = position.coords.latitude;
    var longitude = position.coords.longitude;



    $.ajax({
    type:'POST',
    url:'getLocation.php',
    data:'latitude='+latitude+'&longitude='+longitude,
    success:function(msg){
    if(msg){
    $("#location").html(msg);
    }else{
    $("#location").html('Not Available');
    }
    }
    });


    }
    </script>
    <style type="text/css">
    p{ border: 2px dashed #009755; width: auto; padding: 10px; font-size: 18px; border-radius: 5px; color: #FF7361;}
    span.label{ font-weight: bold; color: #000;}
    </style>
    </head>
    <body>
    <p><span class="label">Your Geo-location:</span> <span id="location"></span></p>
    </body>
    </html>

    mentre il file php "getLocation.php"

    <?php
    if(!empty($_POST['latitude']) && !empty($_POST['longitude'])){
    //Send request and receive json data by latitude and longitude
    $url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.trim($_POST['latitude']).','.trim($_POST['longitude']).'&sensor=true';
    $json = @file_get_contents($url);
    $data = json_decode($json);
    $status = $data->status;
    if($status=="OK"){
    //Get address from json data
    $location = $data->results[0]->formatted_address;
    }else{
    $location = '';
    }
    // dipslay address
    echo $location;
    }
    ?>

    Praticamente il primo file non apre il secondo perchè?
    o c'è un altro modo per farlo?
    Grazie Alberto

  2. #2
    Moderatore di Javascript L'avatar di ciro78
    Registrato dal
    Sep 2000
    residenza
    Napoli
    Messaggi
    8,505
    Ciao Alberto,
    ti invito a leggere il regolamento. Così come hai postato la discussione non va bene. Per problemi tecnici non posso intervenire.

    Aggiungo un dettglio. Se non puoi modificare quanto hai scritto rispondi con il codice bene formattato.
    Ciro Marotta - Programmatore JAVA - PHP
    Preferisco un fallimento alle mie condizioni che un successo alle condizioni altrui.


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.