<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>
<script runat="server">
// ORIGINAL SOURCE: http://www.codeproject.com/KB/webforms/GoogleStaticMapWebControl.aspx?fid=1216153&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2601991#xx2601991xx
void Page_Load()
{
string centerPoint = Request["centerPoint"].ToString();
string apiKey = "YOUR_GOOGLE_MAPS_API_KEY_HERE";
string locationUrl = "http://maps.google.com/staticmap?center=" + centerPoint
+ "&markers=" + centerPoint + ",blue"
+ "&size=300x200"
+ "&maptype=mobile"
+ "&format=png32"
+ "&sensor=true"
+ "&key="+apiKey;
byte[] imageByte = GetImage(locationUrl);
Response.Clear();
Response.ContentType = "image/png";
Response.OutputStream.Write(imageByte, 0, imageByte.Length);
Response.OutputStream.Flush();
Response.End();
}
static public byte[] GetImage(string pageUrl)
{
byte[] returnVal = null;
try
{
Stream ImageStream = new WebClient().OpenRead(pageUrl);
int count = 0;
while (ImageStream.ReadByte() != -1)
count++;
ImageStream.Close();
Stream ImageStream2 = new WebClient().OpenRead(pageUrl);
byte[] temp = new byte[count];
int count2 = 0;
int bt = 0;
while ((bt = ImageStream2.ReadByte()) != -1)
{
temp[count2] = Convert.ToByte(bt);
count2++;
}//end while
ImageStream2.Close();
returnVal = temp;
}
catch (Exception e) { }
return returnVal;
}
</script>