Skip to content

Instantly share code, notes, and snippets.

@kyletaylored
Last active February 8, 2019 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyletaylored/2ff2b633269a3006dd75c472802d1515 to your computer and use it in GitHub Desktop.
Save kyletaylored/2ff2b633269a3006dd75c472802d1515 to your computer and use it in GitHub Desktop.
Get public ip location data using jQuery or Vanilla JS
// jQuery
(function($) {
$(document).ready(() => {
$.get("https://ipinfo.io/json").done((loc) => {
console.log(loc);
});
})
})(jQuery);
// Fetch (VanillaJS)
fetch("https://ipinfo.io/json").then((resp) => {
resp.text().then((body) => {
console.log(body);
});
});
/*
SAMPLE RESULTS
{
"ip": "70.118.23.162",
"hostname": "rrcs-70-118-23-162.sw.biz.rr.com",
"city": "Coppell",
"region": "Texas",
"country": "US",
"loc": "32.9673,-96.9805",
"postal": "75019",
"org": "AS11427 Charter Communications Inc"
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment