Created
May 19, 2011 02:30
-
-
Save nolman/980067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Craigslist google maps mashup</title> | |
<script type="text/javascript" src="javascripts/jquery-1.4.4.min.js"></script> | |
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
var latlng = new google.maps.LatLng(-34.397, 150.644); | |
var reverse_geocoder = new google.maps.Geocoder(); | |
reverse_geocoder.geocode({'address': 'San Francisco CA'}, function(result){ | |
var myOptions = { | |
zoom: 8, | |
center: result[0].geometry.location, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
}; | |
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); | |
map.setZoom(13); | |
var count = 0; | |
var add_marker = function(location, address_info, address_string){ | |
var header = "<a target='new_window' href='" + address_info.requested_url + "'>" + address_string + "</a>"; | |
var marker = new google.maps.Marker({ | |
position: location, | |
map: map | |
}); | |
var infowindow = new google.maps.InfoWindow({ | |
content: header | |
}); | |
google.maps.event.addListener(marker, 'click', function(){ | |
infowindow.open(map,marker); | |
}); | |
} | |
var add_pin_points = function(new_address, address_info){ | |
count +=1; | |
setTimeout(function(){ | |
reverse_geocoder.geocode({'address': new_address}, function(address_geocoded, status){ | |
if(address_geocoded && address_geocoded[0]){ | |
var location = address_geocoded[0].geometry.location; | |
$.post("/key_value_pairs", { key: new_address, value: location.toUrlValue() }); | |
add_marker.call(this, location, address_info, new_address); | |
} | |
}); | |
}, count * 1000); | |
} | |
$.getJSON("http://localhost:9292/proxies/as_json?url=http://sfbay.craigslist.org/sfc/apa/", {'parse':{'link[]':{'path':'.//blockquote/p/a', 'attribute': 'href'}}}, function(link_response){ | |
$.each(link_response.data.link, function(index, value){ | |
$.getJSON("http://localhost:9292/proxies/as_json", {'url':value, 'parse':{'address[]':{'path':'.//comment()'}}}, function(address_info){ | |
address_info = address_info.data; | |
var address_string = $.map(address_info.address, function(n,i){ | |
var address_portion = $.trim(n.split("=")[1]).replace(/\./, "").replace(/\//,""); | |
if (address_portion == "on"){ | |
return null; | |
} | |
return address_portion; | |
}).join(" "); | |
if(address_string && $.trim(address_string) != ""){ | |
var key = address_string; | |
$.getJSON('/key_value_pairs/' + escape(address_string), function(data){ | |
if(data['key']){ | |
var location = new google.maps.LatLng(data['value'].split(',')[0], data['value'].split(',')[1]); | |
add_marker.call(this, location, address_info, address_string) | |
} | |
else{ | |
add_pin_points.call(this, address_string, address_info); | |
} | |
}); | |
} | |
}); | |
}); | |
}); | |
}); | |
}); | |
</script> | |
<style type="text/css"> | |
html { height: 100% } | |
body { height: 100%; margin: 0px; padding: 0px } | |
#map_canvas { height: 100% } | |
</style> | |
</head> | |
<body> | |
<div id='map_canvas' style="width:100%; height:100%"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment