如何从Google静态地图API获取图片

4

我使用这段代码从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#调用此功能以生成并保存图像是否可行?我找不到获取图像对象的方法。


这是一个 Web 应用程序吗(您使用了 asp.net-mvc 标签)?如果是,那么您会生成一个 img 标签并让浏览器获取图像,还是您需要在服务器端处理它? - Kris Vandermotten
是的,我需要在服务器端进行操作。我接受了@L.B的答案。 - 1110
1个回答

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

你是一个圣人! - mathgenius

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接