'Uncaught ReferenceError: curl_init is not defined google maps api

I used the google maps api to get the driving distance between 2 points 1 - The Origin point -> my current location. 2 - The destination point -> The user can choose from the autocomplete api.

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&key=MY_API_KEY&libraries=places"></script>

For Autocomplete and get the destination lat+long

    google.maps.event.addDomListener(window, 'load', initialize);
function initialize() {
var input = document.getElementById('address');
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.addListener('place_changed', function () {
var place = autocomplete.getPlace();
 
    var lat1 = 'CURRENT_LOCATION_LAT';
    var long1 = 'CURRENT_LOCATION_LONG';

    var lat2 = place.geometry['location'].lat();
    var long2 = place.geometry['location'].lng();

    document.getElementById("latitude").value = lat2;
    document.getElementById("longitude").value = long2;

    document.getElementById("distance").innerHTML = GetDrivingDistance(lat1, lat2, long1, long2);

});
}

To get the driving distance

function GetDrivingDistance(lat1, lat2, long1, long2)
{
    $url = 'https://maps.googleapis.com/maps/api/distancematrix/json?origins=' + lat1 , long1 + '&destinations=' + lat2 , long2  + '&mode=driving&language=pl-PL';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $response = curl_exec($ch);
    curl_close($ch);
    $response_a = json_decode($response, true);
    $dist = $response_a['rows'][0]['elements'][0]['distance']['text'];
    $time = $response_a['rows'][0]['elements'][0]['duration']['text'];

    //return array('distance' => $dist, 'time' => $time);
    //return array[$dist,$time];

    //return array['distance' > $dist, 'time' > $time];

    const thedist = [$dist, $time];
    return text = thedist.toString();    
}

Autocomplete API is working fine and I successfuly got the distination lat+long.

But i can't get the driving distance and i got the following error in the consol :

Uncaught ReferenceError: curl_init is not defined

any one can help ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source