2015-08-25 152 views
0

我試圖從Bing地圖獲取圖釘的靜態圖像並顯示某些個人的位置。我正在使用bing提供的圖像api,並且基本上使用他們的簡單示例代碼,但我得到的是";?>而不是圖像。爲什麼不顯示圖像?

<html> 
    <head> 
    <title>Driver Locations</title> 
    </head> 
<body> 
    <?php 

    $latitude = "40.59507828"; 
    $longitude = "-73.78302689"; 
    $key = ""; 
    $imageryBaseURL = "http://dev.virtualearth.net/REST/v1/Imagery/Map"; 

    $pushpins = "&pp="; 
    $mapsize = "?mapSize=800,600"; 
    $ppStyle = ";47;"; 

    $imagerySet = "Road"; 
    $JulieCP = $latitude.",".$longitude; 
    $JuliePP = $JulieCP.$ppStyle."JULIE"; 
    $zoomLevel = "15"; 

    $latitude = "40.90421779"; 
    $longitude = "-73.86591633"; 
    $MarkCP = $latitude.",".$longitude; 
    $MarkPP = $MarkCP.$ppStyle."MARK"; 


    //http://dev.virtualearth.net/REST/v1/Imagery/Map/Road?mapSize=800,600&pp=40.59507828,-73.78302689;47;JULIE&pp=40.90421779,-73.86591633;47;MARK&key=$key 

    echo "<img src='".$imageryURL = $imageryBaseURL."/".$imagerySet."?mapSize=800,600".$pushpins.$MarkPP.$pushpins.$JuliePP."&key=".$key."'>"; 

    ?> 
</body> 
</html> 
+0

這是一個'.php'文件?瀏覽器的全部源代碼是什麼樣的? – chris85

+0

這是完整的數據源。我想要的只是顯示圖像。是的,這是一個'.php'文件。我也有一個html版本,但它是相同的代碼並返回相同的結果。 – Haru

+0

什麼是'$ longtiude'?你拼錯它... 什麼是'$ imageryURL'?你錯了嗎? –

回答

0

你殺了我與所有這些變量:)難怪你不能將它輸出正確...

嘗試下面的語法來代替。我開始正確地編寫可變訂單,但最後放棄了,因此您需要對其進行更正以適應您的需求。語法應該是正確的:

echo "<img src=\"{$imageryBaseUrl}/{$imagerySet}{$mapsize}{$JuliePP}{$ppStyle}{$MarkPP}&key={$key}\">" 

請記住,當變量被存儲在雙引號內,他們還在評估,這使得它更容易閱讀,而不必與時間段來連接。花括號用於分隔變量名稱。如果花括號不在那裏,它將被認爲是一個變量。

編輯:

我跑你的代碼上http://phpfiddle.org/,它僅輸出的畫面,所以代碼似乎是正確的格式,但控制檯想出了一個401(未授權)錯誤。密鑰是否需要填寫才能正確工作?

0

我認爲你有的網址: http://dev.virtualearth.net/REST/v1/Imagery/Map/Road?mapSize=800,600&pp=40.59507828,-73.78302689;47;JULIE&pp=40.90421779,-73.86591633;47;MARK&key=$key被拒絕。

結果是:

{"authenticationResultCode":"NoCredentials","brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png","copyright":"Copyright © 2015 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.","errorDetails":["Access was denied. You may have entered your credentials incorrectly, or you might not have access to the requested resource or operation."],"resourceSets":[],"statusCode":401,"statusDescription":"Unauthorized","traceId":"8782486bb4cc49388954a152f95ce666|HK20271556|02.00.196.1900|"} 

消息:This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.

你需要給你的憑據使用它。你有嗎?