使用PHP cURL将GET请求发送到MapQuest

时间:2019-07-26 16:02:43

标签: php curl get mapquest

我正在尝试通过该网址使用MapQuest获取地图

https://www.mapquestapi.com/staticmap/v5/map?key={key here}&center=30.047565,31.243452&size=@2x&zoom=14&type=light&locations=30.047565,31.243452&defaultMarker=marker-sm-3B5998-22407F

根据文档记录,结果是图像

https://developer.mapquest.com/documentation/static-map-api/v5/map/

当我使用POSTMAN时,我得到一个图像(没有要解析的json数据),当我将此代码用作图像时,地图有时不显示

 <img style="width: 100%; height: 450px; overflow: hidden" src="https://www.mapquestapi.com/staticmap/v5/map?key={key here}&center=30.047565,31.243452&size=1280,400@2x&zoom=18&type=light&locations=30.047565,31.243452&defaultMarker=marker-sm-3B5998-22407F">

所以我正尝试使用PHP cUrl来获取它

curl_setopt_array($curl, [
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_URL => 'https://www.mapquestapi.com/staticmap/v5/map?key={key here}&center=30.047565,31.243452&size=1280,400@2x&zoom=18&type=light&locations=30.047565,31.243452&defaultMarker=marker-sm-3B5998-22407F',
        CURLOPT_USERAGENT => 'Codular Sample cURL Request'
    ]);

    $resp = curl_exec($curl);

    curl_close($curl);
    print_r($resp); 

但是我得到位图或图像代码之类的东西,如何将其显示为图像?

enter image description here

1 个答案:

答案 0 :(得分:0)

您需要具有其响应所提供的标头,尤其是Content-Type标头。

function IsIbanValid(iban) {
    // example "FR76 1020 7000 2104 0210 1346 925"
    //         "CH10 0023 00A1 0235 0260 1"

    var keyIBAN = iban.substring(2, 4);    // 76
    var compte = iban.substring(4, iban.length );
    var compteNum = '';
    compte = compte + iban.substring(0, 2);

    // convert  characters in numbers
    var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for (i = 0; i < compte.length; i++) {
        if (isNaN(compte[i]))
            for (j = 0; j < alphabet.length; j++) {
                if (compte[i] == alphabet[j])
                    compteNum += (j + 10).toString();
            }
        else
            compteNum += compte[i];
    }
    compteNum += '00';   // concat 00 for key  
    // end convert

    var result = modulo(compteNum, 97);

    if ((98-result) == keyIBAN)
        return true;
    else
        return false;
}

/// modulo for big numbers, (modulo % can't be used)
function modulo(divident, divisor) {
    var partLength = 10;

    while (divident.length > partLength) {
        var part = divident.substring(0, partLength);
        divident = (part % divisor) + divident.substring(partLength);
    }

    return divident % divisor;
}