我有一个用于注册用户的 PHP 脚本,但在此过程中,我尝试调用 Google GEOCoding javascript 方法来返回客户端纬度/经度并将其记录到数据库,然后再继续我的 PHP 注册过程。
可以这样做还是有更好的方法?
我当前的代码如下所示:
private function process() {
$this->validate();
$this->register();
// execute javascript here to record lat/lng coordinates to the DB.
$this->goHome();
}
最佳答案
您不需要 JavaScript。 Google 地理编码 API 是一项网络服务。在 PHP 中,只需执行 file_get_contents()
并使用正确的 url 格式发出请求,如 described here 。然后,您需要通过 PHP 的 json_decode()
运行结果.
关于php - 我可以在 PHP 中等待 js 进程后再继续吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13954663/