Skip to content

Instantly share code, notes, and snippets.

@wmora
Created July 26, 2013 02:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmora/6085734 to your computer and use it in GitHub Desktop.
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
<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>
$(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 + '!');
}
});
});
});
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