Skip to content

Instantly share code, notes, and snippets.

@tkiefhaber
Created April 15, 2014 19:23
Show Gist options
  • Save tkiefhaber/10762321 to your computer and use it in GitHub Desktop.
Save tkiefhaber/10762321 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
</head>
<body>
<p id="demo">Click the button to get your coordinates:</p>
<p id="closest"></p>
<button onclick="getLocation()">Try It</button>
<script>
var demo = document.getElementById("demo");
var closest = document.getElementById("closest");
function getLocation() {
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else {
x.innerHTML="Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
demo.innerHTML="Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude
var yelp_url = 'http://api.yelp.com/business_review_search?term=pizza&lat=' + position.coords.latitude + '&long=' + position.coords.longitude + '&limit=1&ywsid=6CWb41GEBQ8nZXu8KaInyw'
$.ajax({url: yelp_url, success: function(result){
alert(result);
closest.innerHTML="hello";
} });
}
</script>
</body>
</html>
@mrgilman
Copy link

What if you:

$.ajax({url: yelp_url}).done(function(result){
    alert(result);
    closest.innerHTML="hello";
});

@mrgilman
Copy link

or even:

$.get(yelp_url).done(function(result){
    alert(result);
    closest.innerHTML="hello";
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment