Mashup of the Day: GeoCode

November 21st, 2008

Mashup of the Day

A simple geocode tool that I wrote 3 years back just won the “Mashup of the Day Award” by the site mashupawards.com!

The tool is very basic – it allows you to look up the latitude and longitude of any address (well, any address that is supported by the Yahoo Geocode API). It came in handy when I needed to find some lat/lng pairs for another app I was building…and so I put it the tool out there for people to use. This was back in the day when Google had just released their mapping API, but didn’t have a public geocode API. Ahh…the good ole days.

I’m not sure how/why it won the award, but the good folks at outside.in just linked to it from their new API page…so I’m guessing that’s where the interest came from. I had forgotten about it!

I added a few more news categories to the AP News mashup. It now plots the following AP feeds on the Google map:

  • National News
  • Sports
  • Business
  • Technology
  • Strange

You can also toggle the news categories on the map so that you can show/hide the various pins. Hopefully it’s a little more useful now…

The AP News Mashup I put together last weekend was mentioned in the Where in the World… Wall Street Journal article (sub. required) yesterday.

81Nassau.com/apnews
This map plots the locations of recent U.S. news stories from the Associated Press. Users can click on each location to view the first few sentences of the story or link to the full article.

Thanks to the author Jessica Vascellaro for the mention!

I put an app together this weekend that geocodes an address from an input form and displays the location on a Google map. I’ve cleaned it up a little and put it online for anyone who’s interested…

http://81nassau.com/demos/geocode/

The app consists of a simple HTML form that allows you to input street, city and state. The lookup/submit button on the form initiates an XmlHttpRequest (ajax) to a simple PHP proxy script that I wrote. The PHP script takes the form input (street, city, state) and creates a Yahoo! Geocode REST request, and makes the request to the Yahoo! geocode service. The script then returns the Yahoo! XML data back to the browser. Some javascript is used to parse the XML from Yahoo! and put the lat, lng and zip on the form. A pin is also drawn on the map (Google).

Below is the code for the simple PHP proxy. Feel free to take/use the code as well as the html/javascript. Just do a view-source on the demo link above to see the html/javascript. Please note that there is minimal error checking in all of the code…add where needed.

Enjoy!


< ?php
 
// Simple proxy script for Yahoo! Geocode API
// Note: there is no error checking done on the input or return from Yahoo!
 
header('Content-type: text/xml');
 
$street = $_REQUEST["street"];
$city   = $_REQUEST["city"];
$state  = $_REQUEST["state"];
 
$url = 'http://api.local.yahoo.com/MapsService/V1/geocode?appid=YOUR_APP_ID_GOES_HERE' .
                '&street=' . urlencode($street) .
                '&city=' . urlencode($city) .
                '&state=' . urlencode($state);
 
$xml = get_content($url);
 
print $xml;
 
function get_content($url)
{
        $string = '';
        $handle = fopen($url, "r");
        if ($handle)
        {
                // php 5
                $string = stream_get_contents($handle);
 
                /* php4
                while (!feof($handle)) {
                    $string .= fread($handle, 8192);
                }
                */
              
                fclose($handle);
        }
        return $string;
}
 
?>

XML Weather Feeds

September 2nd, 2005

Yahoo Weather

Yahoo just released rss weather feeds: http://weather.yahoo.com/rss.

This is fantastic. You can get current conditions as well as five-day forecast data. This is the same feed that is used by the Konfabulator widget.

The format of the URL for the feed is:

http://xml.weather.yahoo.com/forecastrss?p=USNY0996&u=f

p is a US zip or a Yahoo! Weather location ID
u is the temp. units. ‘F’ for Fahrenheit (default) and ‘C’ for celcius

A nice little addition to the feed is the latitude and longitude tags…

Here is a quick and dirty perl script that grabs the rss feed for my zip (10013) and prints the curr conditions and forecast to the screen. No error checking done (for readability)…

 
#!/usr/bin/perl -w
 
# grab weather xml from yahoo rss feed
 
use strict;
use LWP::Simple;
use XML::XPath;
 
my $data_url =
"http://xml.weather.yahoo.com/forecastrss?p=10013&u=f";
 
# get data and drop it in a file
my $xml_data = get ($data_url);
 
# use XPath to parse the file
my $xp = XML::XPath->new(xml => $xml_data);
 
# no error checking...
 
# current conditions
my $curr_cond =
$xp->find('/rss/channel/item/yweather:condition')->get_node(1);
 
print $curr_cond->find('@text') . ": " .
      $curr_cond->find('@temp') . "\n\n";
 
# forecast
foreach my $forecast ($xp->find('/rss/channel/item/yweather:forecast')->get_nodelist)
{
  print $forecast->find('@day') . ": " .
        $forecast->find('@text') . ". " .
        "High " . $forecast->find('@high') . ", " .
        "Low "  . $forecast->find('@low') . "\n";
}

National Weather Service

The National Weather Service has XML weather feeds available at http://www.weather.gov/xml/. You can get current conditions, forecasts, watch/warnings, etc… The current conditions have a REST API while the forecasts are SOAP.

For current conditions/observations, they have both RSS and CAP/XML feeds.
Examples of the feeds:
Central Park NYC RSS Feed
Central Park NYC XML Feed

Weather.com

You can sign up to get access to weather.com’s current conditions and forecast feeds at http://www.weather.com/services/xmloap.html. During the signup, they ask you what type of application the data will be used in and they throw a few pages of lame offers at you (“Sign me up for Timely Gardening Tips from Miracle-Gro”). wtf!?

I think the original Konfabulator widget used the weather.com feed…I seem to remember poking through the javascript at one point. Anyway, no need to go through the signup process for weather.com when you can use the Yahoo! or NWS feeds.

WeatherBug

WeatherBug released their weather API (REST) a few months ago: http://api.weatherbug.com/default.aspx.

You have to sign up and get a license code to use it.

According to the site, you can access:

Google Maps Mashups

May 24th, 2005

Some cool hacks using google maps have come out in the past few weeks. Two in particular are the craigslist/google maps combo HousingMaps and the Chicago Crime site that allows you to track the location of the latest crimes in the Chicago area. There are plenty other cool mashups that have come out as well. I love the craigslist/gmaps combo — that’s the perfect way to search for housing using craigslist.

I’ve always thought that real estate is a great space for a location based app. You could get housing information and directions on your phone/pda while driving or walking around looking at homes. The app could provide you with info, say directions to open houses, based on some profile you create (possibly online). Nothing too exciting, but could be done pretty easily I think.

Anyway, back to google maps… After seeing the craigslist/gmaps hack last week, I tried to put throw together a little map of my own. We need a mapping component for the new application we’re working on, so I wanted to see how google’s works. I love how you can stay in the map and move in any direction by just dragging your mouse. It’s fun to explore manhattan that way using the satellite maps. Such a cool app. There are a few tutorials out there explaining how google’s mapping tech works (java script, xml over http, etc) and someone put together a demo [rancidbacon.com] on how to add your own custom data to google maps. After playing around with it a little bit last week, I put together a lame map that has an image of my building. I know…pretty weak, but it was very easy to set up.

Since we need a mapping component for the application we’re trying to put together, I need to start researching mapping solutions. I’m not sure what some of the providers change in terms of cost or if there are any decent free/open source services. I have a lot to learn there. How nice would it be if google opened up their maps as a web service to outside developers? Some easy APIs that allow anyone to put custom images and tags on maps, along with their own directions/routes, would be nice. I know I’m dreaming on that one…. I can’t imaging google’s mapping data providers (Navteq, Tele Atlas, ?) are too happy with google letting developers use their data for free. And, even if google did open it up to developers, you’d probably be under the similar 1000 hits/day restriction as their other web services. I wonder if they’d ever offer a commercial service…