2012-07-21 62 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

相关问题