var asyncParameter = false; function getGeolocation(callback, apiKey) { request('json', callback, apiKey); } function addUrlParameter(parameters, parameterName, parameterValue) { if (parameters) { parameters = parameters.concat('&', parameterName, '=', parameterValue); } else { parameters = '?'.concat(parameterName, '=', parameterValue); } return parameters; } function request(subUrl, callback, apiKey) { var urlParameters = ''; if (!subUrl) { callback(JSON.parse("{'status': 401, message: 'Given path to IP Geolocation API is not valid'}")); return; } if (apiKey) { urlParameters = addUrlParameter(urlParameters, 'key', apiKey); } var apiEndpoint = 'https://pro.ip-api.com/'.concat(subUrl, urlParameters, ''); jQuery.ajax({ global: false, async: false, method: 'GET', url: apiEndpoint, contentType: 'application/json', dataType: 'json', success: function (result, status, xhr) { var geoDataInfo = result; if (callback) { callback(geoDataInfo); } }, error: function (xhr, status, error) { if (callback) { callback(JSON.parse(xhr.responseText)); } } }); } /** * AnalyticsLogic.com Geo Location SDK for IP-API.com */