IpForensics
HomeGoto Dashboard
  • 📖Introduction
  • Protocols
    • HTTP Json Protocol
    • Response headers
    • Error Codes
  • Features
    • Pay-As-You-Go
    • API Security
    • HTTPS
  • Api Response Data
    • 📶Mobile Carrier
    • 🏥ASN
    • 📊General
    • ⏲️Timezone
    • 💵Currency
    • 👨‍💻Threat Detector
    • 🌐Company
    • 🌏Geolocation
    • 🌍Advance Geolocation
    • 💻Device Information
    • ✈️IATA/ICAO
  • API
    • 🚀Intro
    • 📊IP & Threat Intelligence API
      • Single Lookup
      • Origin Lookup
    • 💹Exchange Rate API
      • Currency Endpoint
      • Live Rate Endpoint
      • Historical Rate Endpoint
      • Currency Conversion Endpoint
      • Currency Swap Endpoint
  • Code Implantation
    • Block Automated Visits From Hosting Providers
    • Block VPN/Proxy and Tor users
    • Redirect by Country and Location Offers
    • Content Personalisation
    • Get the location from an IP Address in Javascript
    • How to get a client's IP address using JavaScript
    • HTML5 Geolocation with IpForensics fallback
    • Blocking Users by Country
    • Detecting Users Currency or Currency Personalisation
    • Preventing Free Trial Abuse
    • Device-Based Ads and App Binary
    • Detect Users Device/Computer and Operating System
    • Detect visitors from EU countries
    • How to detect and prevent credit card fraud
    • How to convert amounts to website visitor currency
  • MISC
    • Changelog
    • FAQs
    • Troubleshooting
    • API Status
    • Rate Limits
Powered by GitBook
On this page

Was this helpful?

  1. Code Implantation

Get the location from an IP Address in Javascript

How to get the location from an IP Address in Javascript and JQuery.

One of ipdata's most useful features is that if you use it client-side with Javascript you don't have to pass in the user's IP address. We will automatically get the user's IP Address, geolocate it and return the geolocation data to you client-side.

An example request in JQuery

$.get("https://ipforensics.net/api/v1/origin?apikey=APIKEY", function(response) {
    console.log(response.meta_data.geolocation);
}, "jsonp");

A simple call like above without passing in any parameters other than the API key will give you the location of the user currently on the page with the above code embedded.

Pure Javascript

var request = new XMLHttpRequest();

request.open('GET', 'https://ipforensics.net/api/v1/origin?apikey=APIKEY');

request.setRequestHeader('Accept', 'application/json');

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log(this.responseText);
  }
};

request.send();

You can pretty much used any programming language of choice to get user location by just making a get HTTP request to IpForensics endpoint.

PreviousContent PersonalisationNextHow to get a client's IP address using JavaScript

Last updated 2 years ago

Was this helpful?

Always reference the for complete response result

API endpoint