Created
June 21, 2010 23:04
-
-
Save bradjohansen/447672 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
/* | |
Script: BA-Awareness Hospital Map | |
Purpose: Use Google Maps to pinpoint hospitals from US News. | |
*/ | |
//Events--------------- | |
window.onload = onLoad; | |
//Events--------------- | |
function onLoad() | |
{ | |
//Event called when page loads. | |
if(document.getElementById('locationBox').value != "Enter your location. (Zip Code or City and State)") | |
{ | |
document.getElementById('locationBox').style.color = "#000000"; | |
} | |
} | |
function locationBoxClick() | |
{ | |
var boxVal = document.getElementById('locationBox').value; | |
if(boxVal == "Enter your location. (Zip Code or City and State)") | |
{ | |
document.getElementById('locationBox').value = ""; | |
document.getElementById('locationBox').style.color = "#000000"; | |
} | |
} | |
function locationBoxBlur() | |
{ | |
var boxVal = document.getElementById('locationBox').value; | |
if(boxVal == "") | |
{ | |
document.getElementById('locationBox').value = "Enter your location. (Zip Code or City and State)"; | |
document.getElementById('locationBox').style.color = "#666"; | |
} | |
} | |
function submitLocationForm() | |
{ | |
submitForm(); | |
return false; | |
} | |
function submitForm() | |
{ | |
var boxVal = document.getElementById('locationBox').value; | |
document.getElementById('locationBox').style.color = "#000000"; | |
if(boxVal == "Enter your location. (Zip Code or City and State)") | |
{ | |
document.getElementById('locationBox').style.color = "#d90000"; | |
} | |
else | |
{ | |
document.getElementById('locationBox').disabled = true; | |
$("#submitLocation").fadeOut(300); | |
//document.getElementById('submitLocation').style.display = "none"; | |
setTimeout('$("#loader").fadeIn(300);', 300); | |
//document.getElementById('loader').style.display = ""; | |
//Do AJAX Request in jQuery | |
$.post("/hospitals", {location:boxVal}, function(data) | |
{ | |
if(data != "error") | |
{ | |
var params = data.split("||"); | |
var lat = params[0]; | |
var lng = params[1]; | |
var points = params[2].split("^^"); | |
var latlng = new google.maps.LatLng(lat, lng); | |
var myOptions = { | |
zoom: 5, | |
center: latlng, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
}; | |
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); | |
document.getElementById('map_canvas').style.display = ""; | |
for(var i = 0; i < points.length; i ++) | |
{ | |
var point = points[i]; | |
var pointParams = point.split(","); | |
var pointLoc = new google.maps.LatLng(pointParams[1], pointParams[2]); | |
var infowindow = new google.maps.InfoWindow({ | |
content: pointParams[3] | |
}); | |
var marker = new google.maps.Marker({ | |
position: myLatlng, | |
map: map, | |
title:pointParams[0] | |
}); | |
google.maps.event.addListener(marker, 'click', function() { infowindow.open(map, marker);}); | |
} | |
} | |
}); | |
} | |
} |
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
<?php | |
include ("htmlparser.inc"); | |
$location = $_REQUEST['location']; | |
//Figure out if location is zip code or city and state | |
$latLngArray = json_decode(file_get_contents("http://maps.google.com/maps/api/geocode/json?address=".$location."&sensor=false"), true); | |
//print_r($latLngArray); | |
$lat = $latLngArray["results"][0]["geometry"]["location"]["lat"] or die("error"); | |
$lng = $latLngArray["results"][0]["geometry"]["location"]["lng"]; | |
echo($lat."||".$lng."||"); | |
if(strlen($location) > 5) | |
{ | |
//Location is city and state | |
//Find comma | |
$locParams = explode(",", $location); | |
$city = $locParams[0]; | |
$state = $locParams[1]; | |
$html = file_get_html('http://health.usnews.com/best-hospitals/search?hospital_name=Hospital+name&specialty_id=IHQGAST&service_offered=All&city='.$city.'&state='.$state.'&zip=Zip&x=74&y=11'); | |
} | |
if(strlen($location) == 5) | |
{ | |
//Location is zip | |
$html = file_get_html('http://health.usnews.com/best-hospitals/search?hospital_name=Hospital+name&specialty_id=IHQGAST&service_offered=All&city=City&state=&zip='.$location.'&x=74&y=11'); | |
} | |
foreach($html->find('div') as $element) | |
{ | |
if($element->class == "result") | |
{ | |
$elementHtml = str_get_html($element->innertext); | |
$newHtml = $elementHtml->find('a', 0); | |
$title = $newHtml->innertext; | |
$locLatLngArray = json_decode(file_get_contents("http://maps.google.com/maps/api/geocode/json?address=".urlencode($title)."&sensor=false"), true); | |
$locLat = $locLatLngArray["results"][0]["geometry"]["location"]["lat"]; | |
$locLng = $locLatLngArray["results"][0]["geometry"]["location"]["lng"]; | |
echo($title."::".$locLat."::".$locLng."::".$elementHtml->innertext."^^"); | |
} | |
} | |
?> |
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
require 'json' | |
require 'cgi' | |
require 'hpricot' | |
require 'open-uri' | |
get '/hospitals' do | |
erb :'hospitals/index' | |
end | |
post '/hospitals/' do | |
def convert_state name, to='name' | |
states =[ | |
{:name => 'Alabama', :abbrev => 'AL'}, | |
{:name => 'Alaska', :abbrev => 'AK'}, | |
{:name => 'Arizona', :abbrev => 'AZ'}, | |
{:name => 'Arkansas', :abbrev => 'AR'}, | |
{:name => 'California', :abbrev => 'CA'}, | |
{:name => 'Colorado', :abbrev => 'CO'}, | |
{:name => 'Delaware', :abbrev => 'DE'}, | |
{:name => 'Florida', :abbrev => 'FL'}, | |
{:name => 'Georgia', :abbrev => 'GA'}, | |
{:name => 'Hawaii', :abbrev => 'HI'}, | |
{:name => 'Idaho', :abbrev => 'ID'}, | |
{:name => 'Illinois', :abbrev => 'IL'}, | |
] | |
states.each do |state| | |
if to == 'name' | |
if state[:abbrev].downcase == name.downcase | |
return state[:name] | |
end | |
elsif to == :abbrev | |
if state[:name].downcase == name.downcase | |
return state[:abbrev].upcase | |
end | |
end | |
end | |
return | |
end | |
location = params[:post][:location] | |
lat_lng_array = JSON.parse("http://maps.google.com/maps/api/geocode/json?address=#{CGI.escape location }&sensor=false") | |
lat = lat_lng_array['results'][0]['geometry']['location']['lat'] | |
lng = lat_lng_array['results'][0]['geometry']['location']['lng'] | |
puts "#{lat}||#{lng}||" | |
if location.length > 5 | |
loc_params = location.split "," | |
city = loc_params[0] | |
state = loc_params[1] | |
state = convert_state state, :abbrev if state.slice(0, 1) == " " | |
puts "#{state}" | |
html = open( "http://health.usnews.com/best-hospitals/search?hospital_name=Hospital+name&specialty_id=IHQGAST&service_offered=All&city=#{city} | |
&state=#{state}&zip=ZIP+Code&x=75&y=18") { |f| Hpricot f} | |
end | |
if location.length == 5 | |
html = open("http://health.usnews.com/best-hospitals/search?hospital_name=Hospital+name&specialty_id=IHQGAST&service_offered=All&city=City&state= | |
&zip=#{location}&x=74&y=11") { |f| Hpricot f} | |
end | |
(html/"div.result").each do |element| | |
element_html = element.to_html | |
new_html = element_html.search("//a") | |
title = new_html.inner_html | |
loc_lat_lng_array = JSON.parse("http://maps.google.com/maps/api/geocode/json?address=#{CGI.escape title}, #{CGI.escape location}&sensor=false") | |
loc_lat = loc_lat_lng_array['results'][0]['geometry']['location']['lat'] | |
loc_lng = loc_lat_lng_array['results'][0]['geometry']['location']['lng'] | |
puts "#{title}::#{loc_lat}::#{loc_lng}::#{element_html.inner_html}^^" | |
erb :"hospitals/index" | |
end | |
end |
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
<script src="../assets/js/hospitals.js"></script> | |
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> | |
<div class="sidebar"> | |
<ul class="subnav"> | |
<li> | |
If you are interested in more information on hospitals for Biliary | |
Atresia you can visit the Top Hospitals listing on | |
<a href="http://health.usnews.com/best-hospitals/rankings/digestive-disorders?page=1"> | |
US News | |
</a> | |
</li> | |
</ul> | |
<!-- follow us on twitter --> | |
<div class="btn-widget"> | |
<a href="http://twitter.com/ba_awareness" title=""> | |
<img src="../images/btn_twitter.png" alt="" /> | |
</a> | |
</div> | |
<!-- // follow us on twitter --> | |
</div> | |
<!-- main-content --> | |
<div class="main-content"> | |
<h1>Hospitals</h1> | |
<h2>Find a Hospital Near You</h2> | |
<!--Hospital Search Tool--> | |
<form onsubmit="return submitLocationForm();"> | |
<input type="text" id="locationBox" value="Enter your location. (Zip Code or City and State)" | |
style="width:300px; color:#666;" onClick="locationBoxClick();" onBlur="locationBoxBlur();"/> | |
<input type="submit" id="submitLocation" value="Search" /><img src="../assets/images/ajax-loader.gif" id="loader" style="display:none; margin-top:2px;" /> | |
</form> | |
<br /> | |
<div id="map_canvas" style="width:500px; height:400px; display:none;"></div> | |
<h3>Under Construction</h3> | |
<p>This page is still under construction</p> | |
<p>I plan on adding an interface where you search | |
using your zip code for top ranked hospitals near your | |
location. You can check out the source on | |
<a href="http://github.com/bradjohansen/ba-awareness.org"> | |
Github | |
</a> | |
<div class="clearfix"></div> | |
</div> | |
<!-- // main-content --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment