Get Geo Location with 2 lines of JavaScript
The Code Things to note: Geo location provided is based on the ip address / location of your ISP. You are reliant on the API service provided by geoplugin.com. Run Directly In Firebug function geoplugin_city() { return 'Dobroyd Point';} function geoplugin_region() { return 'New South Wales';} function geoplugin_regionCode() { return '02';} function geoplugin_regionName() { return 'New South Wales';} function geoplugin_areaCode() { return '0';} function geoplugin_dmaCode() { return '0';} function geoplugin_countryCode() { return 'AU';} function geoplugin_countryName() { return 'Australia';
var jq = document.createElement('script');
jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type.
jQuery.noConflict();
jQuery(document).ready(function($) {
jQuery.getScript('http://www.geoplugin.net/javascript.gp', function()
{
var country = geoplugin_countryName();
var zone = geoplugin_region();
var district = geoplugin_city();
console.log("Your location is: " + country + ", " + zone + ", " + district);
});
});
Read full article from Get Geo Location with 2 lines of JavaScript
The Code Things to note: Geo location provided is based on the ip address / location of your ISP. You are reliant on the API service provided by geoplugin.com. Run Directly In Firebug function geoplugin_city() { return 'Dobroyd Point';} function geoplugin_region() { return 'New South Wales';} function geoplugin_regionCode() { return '02';} function geoplugin_regionName() { return 'New South Wales';} function geoplugin_areaCode() { return '0';} function geoplugin_dmaCode() { return '0';} function geoplugin_countryCode() { return 'AU';} function geoplugin_countryName() { return 'Australia';
var jq = document.createElement('script');
jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type.
jQuery.noConflict();
jQuery(document).ready(function($) {
jQuery.getScript('http://www.geoplugin.net/javascript.gp', function()
{
var country = geoplugin_countryName();
var zone = geoplugin_region();
var district = geoplugin_city();
console.log("Your location is: " + country + ", " + zone + ", " + district);
});
});
Read full article from Get Geo Location with 2 lines of JavaScript
No comments:
Post a Comment