I am trying to receive map image for specific location.
So first, I translated the name into the longitude and latitude. This is working and is done by code below:
string singleLocation = streamReader.ReadLine();
Console.WriteLine(singleLocation);
var requestUri = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", Uri.EscapeDataString(singleLocation));
var request = WebRequest.Create(requestUri);
var response = request.GetResponse();
var xdoc = XDocument.Load(response.GetResponseStream());
var result = xdoc.Element("GeocodeResponse").Element("result");
var locationElement = result.Element("geometry").Element("location");
var lat = locationElement.Element("lat");
var lng = locationElement.Element("lng");
var lat2 = lat.Value;
lat2 = lat2.Replace('.', ',');
double latitude;
double.TryParse(lat2, out latitude);
var lng2 = lng.Value;
lng2 = lng2.Replace('.', ',');
double longitude;
double.TryParse(lng2, out longitude);
Console.WriteLine(latitude + " " + longitude);
And then I am trying to receive an image of map for specific location. And this part is not working properly. I do not know how to handle response.
var requestUri2 = string.Format(
"https://maps.googleapis.com/maps/api/staticmap?center={0}&zoom={1}&size={2}x{3}&maptype=roadmap",
Uri.EscapeDataString(singleLocation),
Uri.EscapeDataString(5.ToString()),
Uri.EscapeDataString(640.ToString()),
Uri.EscapeDataString(640.ToString()));
var request2 = WebRequest.Create(requestUri2);
var response2 = request2.GetResponse();
var map = response2.GetResponseStream();
The application must to just do the work it doesnt need to be pretty or do complex process, neither use good wrapers if it is not required. I would like to just save this map into file like jpg or png.
EDIT: Solution is here: How to use httpwebrequest to pull image from website to local file