0

I would like to implement ManpMyIndia Driving Distance Matrix API in my project. I am developing a webpage where i want distance between 2 latng. below is the ajax for the same.

var url = 'https://apis.mapmyindia.com/advancedmaps/v1/<API_KEY>/distance?center=19.121694747345824,72.85332576871612&pts=19.1209841659807,72.8531851553014&rtype=0';

$.ajax({
    type: "POST",
    dataType: 'text',
    url: "getResponse.php",
    async: false,
    data: {
        url: JSON.stringify(api_url),
    },
    success: function (result) {
        console.log(result);
        var resdata = JSON.parse(result);

        if (resdata.status == 'success') {
            var jsondata = JSON.parse(resdata.data);
            if (jsondata.responseCode == 200) {
                console.log(jsondata.results);
            }
            else {
                var res = 'Something went wrong in the response';
                console.log(res);
            }
        }
        else {
            var error_response = "No Response from API Server. kindly check the keys or request server url"
            console.log(error_response);
        }
    }
});

I am not able to figure it out as what code should be used in getResponse.php. I would want to know what code should i write in getResponse.php. I am new to web development.

Thanks you in advance.

Habib
  • 591
  • 8
  • 29
Akshay Anpat
  • 33
  • 1
  • 9

2 Answers2

0

Use following link and download sample source code where you will get response.php file for you reference:

Link : https://www.mapmyindia.com/api/advanced-maps/doc/distance-api

0

This is the right technique to fetch data using an api in php ,you can work around and modify it in your way.I hope it helps

 $.ajax({
        type: "POST",
        dataType: 'text',
        url: "getResponse.php",
        async: false,
        data: {anydata:anydata},//this can be the latitudes longitudes
        success: function (result) {
            console.log(result);
            var resdata = JSON.parse(result);

           //use the response in the way you want

            }

        }
    });




//getResponse.php
    $data=$_POST['data'];
    //send incoming data with url

        $url ="http://apis.mapmyindia.com/advancedmaps/v1/<licence_key>/distance?<Parameters>"

        $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);
        echo $response_a
        ?>
Shubham Dixit
  • 9,242
  • 4
  • 27
  • 46