Google Distance Matrix API在我的本地服务器上运行,但在主服务器中无法运行

时间:2017-11-20 13:30:56

标签: google-distancematrix-api

我需要计算英国两个地区之间的距离。这就是我使用Google Distance Matrix API的原因。在我的本地主机服务器中它工作正常,但当我在互联网上传它,它无法正常工作。我已经从谷歌获得API密钥,验证我的网站,创建一个项目并在谷歌中添加该密钥。没有什么对我有用。请检查我的代码。

    $postcode1=$this->input->post('postcode1');
    $postcode2=$this->input->post('postcode2');
    $result = array();
    $url = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=$postcode1&destinations=$postcode2&mode=driving&language=en-EN&sensor=false&key=MY_API_KEY";
    $data = @file_get_contents($url);
    $result = json_decode($data, true);
    $distance=$result['rows'][0]['elements'][0]['distance']['text'];
    echo $distance;

0 个答案:

没有答案