0

I need something similar to the code we have where we alert the coordinates but instead save those coordinates into a php file.

 var array = [];
          navigator.geolocation.getCurrentPosition(function(position) {
            var lat = position.coords.latitude;
            var lon = position.coords.longitude;
               array.push(lat, lon); 
                locationCode()         

});

function locationCode() {
   alert(array); 
}                // Try HTML5 geolocation.
        if (navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(function(position) {
            var pos = {
              lat: position.coords.latitude,
            lng: position.coords.longitude

               };
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
joe luna
  • 11
  • 1
  • "_save those coordinates into a php file_" is ambiguous. Do you mean you want to send that data to your PHP script so that it can save it somewhere? – Sherif Aug 24 '16 at 00:30
  • 1
    There is a similar post: [http://stackoverflow.com/questions/12813580/how-to-assign-php-array-values-to-javascript-array](http://stackoverflow.com/questions/12813580/how-to-assign-php-array-values-to-javascript-array) – Victor Aug 24 '16 at 00:31
  • convert to json array in javascript then use php json_decode function – MindGamer Aug 24 '16 at 00:35
  • @Sherif I want to send that data to a php script so I can save it somewhere on a server – joe luna Aug 24 '16 at 00:36
  • Possible duplicate of [Send array with Ajax to PHP script](http://stackoverflow.com/questions/9001526/send-array-with-ajax-to-php-script) – Sherif Aug 24 '16 at 00:46

0 Answers0