My code in js (doesn't work) to transfer data to PHP is:
function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
var input = results[0].geometry.location;
var lat = input.lat();
console.log(lat);
/*var lat = input.lat();
var longitude = input.lng();
document.getElementById("wypisz").innerHTML=lat;
request.open("GET", "address.php?lat=" + lat, true);
//var url = "address.php?lat=latitude&lng =longitude";
//document.getElementById("wypisz").innerHTML = results[0].geometry.location.lng;
*/
$.ajax({
type: "GET",
data: "lat=" + lat,
url:"address.php",
success: function(data) { console.log(data) }
})
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
And to get them in the PHP file :
if(isSet($_GET['lat'])){
echo "param good";
} else {
echo "incorrect";
}
When I print_r
it, it always displays empty Array.
Can you help me make this conversion work?
Here's more of my code, this is the place where I mark specific latitude and longitude:
<div id="panel">
Address :
<input id="address" name = "address" type="textbox" value="Warszawa, Pol">
<input type="button" value="wstaw" onclick="codeAddress()" >
</div>
<div id="map-canvas"></div>
And here I send information to php file:
<input type="submit" id = "ff" value="Send information">