c# google static mapas api

本文关键字:api mapas static google | 更新日期: 2023-09-27 18:31:18

大家好,我用静态谷歌地图在 MVC C# 中编码,我可以显示地图并显示坐标的图片,但我无法在我的服务器上保存谷歌静态地图 API 的图像,请问如何使用我的控制器上的 image.src("https://maps.googleapis.com/maps/api/staticmap?center=-16.511668,-68.127034&size=640x480&scale=2&maptype=hybrid&zoom=18&markers=-16.511668,-68.127034"中的图像,请帮助

c# google static mapas api

您可以尝试发出 Web 请求,获取 Web 响应并将其写入文件流。下面是一个可能会有所帮助的代码片段:

WebRequest request = WebRequest.Create("url");
var response  = request.GetResponse();
using (Stream dataStream = response.GetResponseStream())
{
    using (FileStream fs = new FileStream(@"file_path", FileMode.OpenOrCreate, FileAccess.ReadWrite))
    {
        dataStream.CopyTo(fs);
    }
}
response.Close();

请务必将"file_path"替换为目标文件夹,将"url"替换为所需资源。让我知道这是否有帮助。