javascript - how can i export the geolocation output to log file? -


i have code displays geolocation (longitude: xx latitude: xx accuracy: xxx) ..how can output results log file log.txt when body visit url

    <!-- <xml version="1.0" encoding="utf-8"> --> <!doctype html public "-//wapforum//dtd xhtml mobile 1.0//en" "http://www.wapforum.org/dtd/xhtml-mobile10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>geolocation api demo</title> <meta content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" name="viewport"/> <script> function successhandler(location) {     var message = document.getelementbyid("message"), html = [];     html.push("<img width='512' height='512' src='http://maps.google.com/maps/api/staticmap?center=", location.coords.latitude, ",", location.coords.longitude, "&markers=size:small|color:blue|", location.coords.latitude, ",", location.coords.longitude, "&zoom=16&size=512x512&sensor=false' />");     html.push("<p>longitude: ", location.coords.longitude, "</p>");     html.push("<p>latitude: ", location.coords.latitude, "</p>");     html.push("<p>accuracy: ", location.coords.accuracy, " meters</p>");     message.innerhtml = html.join(""); } function errorhandler(error) {     alert('attempt location failed: ' + error.message); } navigator.geolocation.getcurrentposition(successhandler, errorhandler); </script> </head> <body> <div id="message">location unknown</div> </body> </html> 

this javascript code send data asynchronously server.

    function successhandler(location) {         var message = document.getelementbyid("message"), html = [];         html.push("<img width='512' height='512' src='http://maps.google.com/maps/api/staticmap?center=", location.coords.latitude, ",", location.coords.longitude, "&markers=size:small|color:blue|", location.coords.latitude, ",", location.coords.longitude, "&zoom=16&size=512x512&sensor=false' />");         html.push("<p>longitude: ", location.coords.longitude, "</p>");         html.push("<p>latitude: ", location.coords.latitude, "</p>");         html.push("<p>accuracy: ", location.coords.accuracy, " meters</p>");         message.innerhtml = html.join("");          //send server         var xmlhttp;             if (window.xmlhttprequest) { // code ie7+, firefox, chrome, opera                 xmlhttp=new xmlhttprequest();             } else { // code ie6, ie5                 xmlhttp=new activexobject("microsoft.xmlhttp");             }              xmlhttp.open("post","script.php",true);             xmlhttp.setrequestheader("content-type", "application/x-www-form-urlencoded; charset=utf-8");             xmlhttp.send("latitude="+location.coords.latitude+"&longitude="+location.coords.longitude+"&accuracy="+location.coords.accuracy); // pass data, assuming lat, long, acc respective js variables     }     function errorhandler(error) {         alert('attempt location failed: ' + error.message);     }     navigator.geolocation.getcurrentposition(successhandler, errorhandler); 

retrieve data on server side , save below php code (script.php)

<?php     $latitude = $_post['latitude'];     $longitude = $_post['longitude'];     $accuracy = $_post['accuracy'];      $string = $latitude." - ".$longitude." | ".$accuracy; // turn 00000 - 00000 | 0.25      $myfile = file_put_contents('log.txt', $string.php_eol, file_append); ?>  

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -