In the post I show how to display your location weather on a Google® Map. Before you begin you will need the your station identifier (look it up here). You will also need a Google Maps API Key for your web site.
You can look at my live example here. I use 2 .asp pages, weathermap.asp and georss.asp, 1 page that requests the viewers station and displays the map and 1 .asp page the gets the weather and write the rss file. Here is the code for the first page (weathermap.asp):
<%
station = Request.Form("station")
If station = "" Then
station = "KDAN"
End If
lat = "39"
lon = "-94"
zoom = "3"
%>
As you can see above I set up a default station and some varaiables. The lat and lon on this page are not the station location but rather where you would like the map centered, these are optional. I also pick a zoom level for the map. This is optional as well. Next I will call the Google map. You can see I load GeoRSS into the Google Map using there "new GGeoXml". I simply call my other .asp file (station.asp) with the station identified in the link.I also set the center and zoom level using my variables "map.setCenter(new GLatLng(<%=lat%>,<%=lon%>), <%=zoom%>);".
<html>
<head>
<title>Weather on a Map</title>
<script language="javascript" src="menu.js" type="text/javascript"></script>
<script src="http://maps.google.com/maps?file=api&v=2&key=YOUR_API_KEY_HERE" type="text/javascript"></script>
<script type="text/javascript">
var map;
var geoXml = new GGeoXml("http://weather4webs.com/georss.asp?station=<%=station%>");
function onLoad() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("mapy"));
// map.addControl(new GLargeMapControl());
map.setCenter(new GLatLng(<%=lat%>,<%=lon%>), <%=zoom%>);
map.addOverlay(geoXml);
}
}
</script>
</head>
Finally I construct the reset of the html in the page which displays the map and a form where the viewer can enter their own station.
<body onload="onLoad()" onunload="GUnload()">
<h1>GeoRSS</h1>
<p>Enter you ICAO Weather Station Identifier below to get your Current Weather Station GeoRSS link.</p>
<div id="mapy" style="width: 600px; height: 300px"></div>
<%
If station <> "" Then
Response.Write("<p>Click on the marker to view the current weather conditions.</p>")
Response.Write("<p>GeoRSS link: <a href=http://weather4webs.com/georss.asp?station=" & station & ">http://weather4webs.com/georss.asp?station=" & station & "</a></p>")
End If
%>
<form method="post" action="weathermap.asp">
<p>4 Letter ICAO Station ID: <input type="text" size="5" name="station" /> <input type="submit" value="Submit" /> <a href="locations.asp">Lookup Tool</a></p>
</form>
My other .asp page (station.asp) gets the weather from NWS and then writes the RSS file. Here is the code:
<%
station = Request.QueryString("station")
Response.CacheControl = "no-cache"
hoster = Lcase(Request.ServerVariables("HTTP_HOST"))
If hoster = "localhost" Then
Set jason = Server.CreateObject ("MSXML2.XMLHTTP")
Else
Set jason = Server.CreateObject ("MSXML2.ServerXMLHTTP")
End If
jason.Open "GET", "http://www.weather.gov/data/current_obs/" & station & ".xml", false
jason.Send
Set xd = Server.CreateObject ("Microsoft.XMLDOM")
xd.async = "false"
xd.loadXML(jason.responsexml.xml)
station_id = xd.getElementsByTagName("station_id").item(0).text
latitude = xd.getElementsByTagName("latitude").item(0).text
longitude = xd.getElementsByTagName("longitude").item(0).text
location = xd.getElementsByTagName("location").item(0).text
observation_time = xd.getElementsByTagName("observation_time").item(0).text
icon_url_name = xd.getElementsByTagName("icon_url_name").item(0).text
wind_string = xd.getElementsByTagName("wind_string").item(0).text
visibility_mi = xd.getElementsByTagName("visibility_mi").item(0).text
weather = xd.getElementsByTagName("weather").item(0).text
temperature_string = xd.getElementsByTagName("temperature_string").item(0).text
dewpoint_string = xd.getElementsByTagName("dewpoint_string").item(0).text
relative_humidity = xd.getElementsByTagName("relative_humidity").item(0).text
pressure_string = xd.getElementsByTagName("pressure_string").item(0).text
disclaimer_url = xd.getElementsByTagName("disclaimer_url").item(0).text
Set xd = Nothing
Set jason = Nothing
%>
<%
Response.ContentType = "text/xml"
%>
<rss version="2.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:ymaps="http://api.maps.yahoo.com/Maps/V2/AnnotatedMaps.xsd">
<channel>
<link>http://weather4webs.com/georss.asp</link>
<title>Weather4Webs.com RSS</title>
<description>Weather for Webs</description>
<item>
<title>Conditions at <%=location%></title>
<link>http://weather4webs.com/current/station.asp?station=<%=station%></link>
<description>Wind is <%=wind_string%>, visibility is <%=visibility_mi%> miles, sky conditions are <%=weather%>, the current temperature is <%=temperature_string%>, dewpoint is <%=dewpoint_string%>, humidity is <%=relative_humidity%>%, and the pressure is <%=pressure_string%>. *<%=observation_time%></description>
<geo:lat><%=latitude%></geo:lat>
<geo:long><%=longitude%></geo:long>
</item>
</channel>
</rss>