Created
July 26, 2013 02:51
-
-
Save wmora/6085734 to your computer and use it in GitHub Desktop.
A CodePen by William Mora. Where am I? - Simple ajax call to demonstrate how to get a client's location using MercadoLibre's APIs
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
<html> | |
<head> | |
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet'/> | |
</head> | |
<body> | |
<h1>Where am I?</h1> | |
<input type='button' id='findme' value='Find me!'/> | |
<br /><br /> | |
<div id='message'></div> | |
</body> | |
</html> |
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
$(document).on('ready', function() { | |
$('#findme').on('click', function() { | |
$('#message').html('Loading...'); | |
$.ajax( { | |
url: "https://api.mercadolibre.com/geolocation/whereami", | |
success: function(data) { | |
var city = data.city_name; | |
var country = data.country_name; | |
$('#message').text("You are in " + city + ", " + country + '!'); | |
} | |
}); | |
}); | |
}); |
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
body { | |
font-family: 'Open Sans', sans-serif; | |
padding: 1em; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment