I want to return Javascript variable in JSON format in PHP.
Below is my Javascript code which returns Longitude and Latitude.
function showPosition(){
        if(navigator.geolocation){
            navigator.geolocation.getCurrentPosition(function(position){
                 var positionInfo = "Your current position is (" + "Latitude: " + position.coords.latitude + ", " + "Longitude: " + position.coords.longitude + ")";
                //document.getElementById("result").innerHTML = positionInfo;
            });
        } else{
            alert("Sorry, your browser does not support HTML5 geolocation.");
        }
    }
    showPosition();
    //document.write(positionInfo);
How can i get the values of variable
position.coords.latitudeandposition.coords.longitudeas response in json format using php
Please note: We are calling this php script in background, so solution of fetching the variables on html input fields is not a viable solution for us.
 
    