[英]Google Maps API results variables into php
我想从JS导出搜索结果变量(纬度和经度)作为php变量。 我知道有必要拥有另一个php文件,例如test.php。
以下变量:
marker.setPlace({
placeId: place.place_id,
location: results[0].geometry.location,
});
marker.setVisible(true);
//infowindowContent.children['place-name'].textContent = place.name;
//infowindowContent.children['place-id'].textContent = place.place_id;
infowindowContent.children['place-address'].textContent =
//results[0].formatted_address;
results[0].geometry.location.lat(),
results[0].geometry.location.lng(),
infowindow.open(map, marker);
});
});
}
您可以简单地将XMLHttpRequest
与ajax和JSON结合使用(用于js和php ),以便将数据传递到您的php文件:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log (this.responseText);
}
};
xhttp.open("GET", "demo_get.asp?marker=" + JSON.stringify (marker) + "&infoWindow=" + JSON.stringify (infowindow), true);
xhttp.send();
然后,在php中:
$marker = json_decode ($_GET["marker"]);
$infoWindow = json_decode ($_GET["infoWindow"]);
// Do stuff...
告诉我您是否有疑问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.