Passing value from javascript to php post

0

I'm having trouble getting my location and moving to the php post with onload . How can I do this ? The values I am trying to capture are google lat and long .

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: -34.397, lng: 150.644},
    zoom: 6
  });
  var infoWindow = new google.maps.InfoWindow({map: map});

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

      infoWindow.setPosition(pos);
      infoWindow.setContent('Location found.');
      map.setCenter(pos);
    }, function() {
      handleLocationError(true, infoWindow, map.getCenter());
    });
  } else {
    // Browser doesn't support Geolocation
    handleLocationError(false, infoWindow, map.getCenter());
  }
}
    
asked by anonymous 14.09.2016 / 23:59

1 answer

0

An example of how you can do it with jquery.ajax (the documentation is on the official website) api.jquery.com/jquery .ajax /

$.ajax({
  method: "POST",
  url: "some.php",
  data: {lat: -34.397, lng: 150.644}
})
.done(function( msg ) {
  alert( "Data Saved: " + msg );
});
    
21.09.2017 / 19:11