Sunlight DataScienceToolkit

Test of the Street to Coordinates API. Scraped 10 foreclosed HUD properties for Lansing Michigan using YQL and geocoded their addresses using DSTK and produced a Google Map Link for each property.

by dandiebolt

HTML

<script src="https://github.com/jquery/jquery-tmpl/raw/master/jquery.tmpl.min.js"></script>
<script src="http://www.datasciencetoolkit.org/scripts/jquery.dstk.js"></script>
<script id="template" type="text/x-jquery-tmpl">
    <ul>
        <li>${content}</li>
        <li><a target="_blank" href="http://maps.google.com/maps?q=${latitude},${longitude}(${content})">Map</a></li>        
    </ul>
    <hr/>
</script>

<div id="info"></div>

JavaScript

var dstk = $.DSTK();

// HUD Homes Query: State=Michigan and City=Lansing
// https://hudhomestore.secureportalk.net/HUD/PropertySearchResult.aspx?zipCode=&city=Lansing&county=&street=&sState=MI&fromPrice=0&toPrice=0&caseNumber=&bed=0&bath=0&buyerType=0&Status=0

// YQL Query:
// SELECT * 
// FROM html 
// WHERE url="https://hudhomestore.secureportalk.net/HUD/PropertySearchResult.aspx?zipCode=&city=Lansing&county=&street=&sState=MI&fromPrice=0&toPrice=0&caseNumber=&bed=0&bath=0&buyerType=0&Status=0" 
// AND xpath='//label[contains(@id,"Label6")]'

// YQL Permalink:
// http://developer.yahoo.com/yql/console/?q=select%20*%20from%20html%20where%20url%3D%22https%3A%2F%2Fhudhomestore.secureportalk.net%2FHUD%2FPropertySearchResult.aspx%3FzipCode%3D%26city%3DLansing%26county%3D%26street%3D%26sState%3DMI%26fromPrice%3D0%26toPrice%3D0%26caseNumber%3D%26bed%3D0%26bath%3D0%26buyerType%3D0%26Status%3D0%22%20and%0A%20%20%20%20%20%20xpath%3D%27%2F%2Flabel%5Bcontains(%40id%2C%22Label6%22)%5D%27&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
          
var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22https%3A%2F%2Fhudhomestore.secureportalk.net%2FHUD%2FPropertySearchResult.aspx%3FzipCode%3D%26city%3DLansing%26county%3D%26street%3D%26sState%3DMI%26fromPrice%3D0%26toPrice%3D0%26caseNumber%3D%26bed%3D0%26bath%3D0%26buyerType%3D0%26Status%3D0%22%20and%0A%20%20%20%20%20%20xpath%3D'%2F%2Flabel%5Bcontains(%40id%2C%22Label6%22)%5D'&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";

$.ajax({
    url: url,
    dataType: 'jsonp',
    success: function(data) {
        var addresses = data.query.results.label;
        $.each(addresses, function(index, address) {
            address.content=address.content.split("\n").slice(0,3).join(" ");
            dstk.street2coordinates(address.content, function(result) {
                $.each(result, function(key, val) {
                    address.latitude =...