Created
April 6, 2014 04:16
-
-
Save bzhang1670/10001477 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> | |
<head> | |
<link href="css/bootstrap.css" rel="stylesheet"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript" id="jquery"></script> | |
</head> | |
<html> | |
<title>localchat</title> | |
<body> | |
<h1>Sorry, we don't have much stuff yet!</h1> | |
<!--- | |
<input type="button" value="Show location" onclick="javascript:showlocation();" /> <br/> | |
Latitude: <span id="latitude"></span> <br/> | |
Longitude: <span id="longitude"></span>----> | |
<br> | |
<div id="names"> | |
</div> | |
<script type="text/javascript"> | |
//<!-- location object --> | |
function location(name, distance, id) { | |
this.name = name; | |
this.distance = distance; | |
this.id | |
} | |
var baseurl="https://api.foursquare.com/v2/venues/search?"; | |
var id="client_id=R3KEC5QXX1QAWWVFDJT32RMJF4GP0CBB3PX5D3DIKFJTR0K5"; | |
var secret="&client_secret=HUO1BXW4Z12ZELV1AGVDSCHV3EE4RVH2EGPFLEKE535VR3JO"; | |
var version="&v=20140405"; | |
var ll="&ll=40.805, -73.961" | |
//<!--var query="&query=sushi"--> | |
var radius="" //<!--"&radius=300"--> | |
var url = baseurl+id+secret+version+ll+radius; | |
document.write(url); | |
getnearestlocation(getlocationArray(url)); | |
function getlocationArray(url) { | |
var locArr = {}; | |
$.getJSON(url, function(data) { | |
$.each(data.response.venues, function(i,venues){ | |
content = "<p>" + "name: " + venues.name + " distance: " + venues.distance + " id: " + venues.id + "</p>"; | |
$(content).appendTo("#names"); | |
var loc = new location(venues.name, venues.distance, venues.id); | |
locArr.push(loc); | |
}); | |
} | |
); | |
return locArr; | |
} | |
//<!-- This will loop through a location array--> | |
function getnearestlocation(locArray) { | |
min=locArray[0]; | |
for(var i = 1; i<locArray.size(); i++) { | |
if(locArray[i].distance > min.distance) { | |
min=locArray[i]; | |
} | |
} | |
return min; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment