API Code Examples

Ready-to-use code snippets and interactive demos for quick integration

Live API Demo

Test our API right here with your own API key or try the demo with a sample response:

Click "Test API" to see live results...

JavaScript Examples

Basic JavaScript with XMLHttpRequest
function getIPLocation(apiKey, ipAddress) {
    const xhr = new XMLHttpRequest();
    const url = `https://www.iptrackeronline.com/json.php?k=${apiKey}&ip_address=${ipAddress}`;

    xhr.open('GET', url, true);
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4 && xhr.status === 200) {
            const data = JSON.parse(xhr.responseText);
            if (data.status === 'success') {
                console.log('Location:', data.data.city, data.data.country);
                console.log('ISP:', data.data.provider);
                console.log('Coordinates:', data.data.latitude, data.data.longitude);
            }
        }
    };
    xhr.send();
}

// Usage
getIPLocation('YOUR_API_KEY', '8.8.8.8');

Common Use Cases

Fraud Detection

Detect suspicious login attempts by comparing user's expected location with IP geolocation data.

if (user_country != ip_location.country) { flag_for_review(); }

Content Localization

Automatically show content in the user's local language and currency based on their location.

currency = getCurrency(ip_data.country); language = getLanguage(ip_data.country);

Analytics Enhancement

Enrich your analytics data with accurate geographic information for better insights.

analytics.track('page_view', { country: ip_data.country, city: ip_data.city });

Geo-blocking

Restrict access to content based on geographic location for compliance or licensing.

if (restricted.includes(ip_data.countrycode)) { show_blocked_message(); }
Need more lookups? View Pricing