2012-07-21 105 views
3

我使用此代碼從Google API生成靜態圖片,但我的請求太多,所以有時候我會從Google中過度使用。如何從Google靜態地圖API獲取圖片

string latlng = location.Latitude + "," + location.Longitude; 
string path = "http://maps.googleapis.com/maps/api/staticmap?center=" + latlng + 
    "&zoom=16&size=200x200&maptype=roadmap&markers=color:blue%7Clabel:S%7C" + 
    latlng + "&sensor=false"; 

是否有可能從C#中調用此函數來生成並保存圖像?我無法找到獲取圖像對象的方法。

+0

這是一個Web應用程序(你用asp.net-mvc做過標記)嗎?如果是這樣,你是否生成一個img標記並讓瀏覽器獲取圖像,或者你需要它服務器端? – 2012-07-21 18:15:51

+0

是的我需要它在服務器端。我接受了@ L.B的回答。 – 1110 2012-07-21 19:46:23

回答

8
using (WebClient wc = new WebClient()) { 
    wc.DownloadFile(url, @"c:\temp\img.png"); 
} 
+0

你是聖人! – mathgenius 2018-03-04 11:38:07