0
votes

hi guys i have coding in mvc c# with static google maps i can show a map and show the picture of the coordenates but i cant save the image of google static maps api on my server, please how can i use the image from 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" on my controller please help

1
Whey you want to save the image? not better just to save the Lat & Long and use it on map when needed ? - Eyal

1 Answers

1
votes

You can just try making a web request, take the web response and write it to a file stream. Here is a code snippet that might help:

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();

Be sure to replace "file_path" to your destination folder and "url" to the required resource. Let me know if this helps.