How to Implement Geofencing Using Fingerprinting API

How to leverage device fingerprinting, and location tracking to enforce geolocation-based rules efficiently

What Is Geofencing?

Geofencing works by defining a geographical perimeter (latitude/longitude coordinates with a radius). When a device enters or exits this virtual boundary, an action is triggered—such as granting or denying access, sending a notification, or flagging a transaction.

Why Use Fingerprinting API for Geofencing?

More Reliable Than GPS

  • GPS can be manipulated using VPNs or spoofing tools.

  • Some users disable location services, limiting app-based geofencing.

  • Fingerprinting API leverages multiple signals, including IP address, network details, and device characteristics, making location tracking more robust.

No App Installation Required

  • Unlike traditional geofencing, which often requires a mobile app, Fingerprinting API works directly in the browser, making it ideal for websites and web applications.

Fraud Prevention

  • Detects VPNs, proxies, and Tor networks attempting to bypass geofencing restrictions.

Ensures transactions or logins happen from expected locations.


Step-by-Step Guide to Implement Geofencing Using Fingerprinting API


1. Set Up Your Fingerprinting API Account

First, sign up at Fingerprinting API and get your API key.


2. Retrieve User’s Location Using Fingerprinting API

Fingerprinting API provides IP-based geolocation, device insights, and network information. To retrieve a user's location, make a request to the API.

Example API Call (Python), based on IP

import requests

API_KEY = "your_api_key"
USER_IP = "8.8.8.8"  # Example IP

url = f"https://api.fingerprinting-api.com/v1/lookup?apiKey={API_KEY}&ip={USER_IP}"

response = requests.get(url)
data = response.json()

print(data)  # Check the geolocation data

Example Response :

{
  "ip": "8.8.8.8",
  "continent": "North America",
  "country": "United States",
  "region": "California",
  "city": "Mountain View",
  "latitude": 37.40599,
  "longitude": -122.078514,
  "isp": "Google LLC",
  "vpn": false,
  "proxy": false,
  "tor": false
}


Other method can be used like user id

3. Define a Geofencing Zone

Option 1: Geofencing by City or Region

Let’s say we want to restrict access to users only within New York City (NYC). We define the geofence with a central latitude/longitude and a radius.

Example: Setting Up a Geofence Around NYC

from geopy.distance import geodesic

# Define geofence (center of NYC and radius in km)
GEOFENCE_CENTER = (40.7128, -74.0060)
GEOFENCE_RADIUS_KM = 50  # 50 km radius

# Extract user's location from API response
user_location = (data["latitude"], data["longitude"])

# Check if user is within the geofence
distance = geodesic(GEOFENCE_CENTER, user_location).km

if distance <= GEOFENCE_RADIUS_KM:
    print("User is inside the geofenced area.")
else:
    print("Access denied. User is outside the geofenced area.")

Option 2: Geofencing by Country

For businesses that need to restrict access based on entire countries (e.g., compliance with regulations or country-specific services), the Fingerprinting API provides country-based filtering. It can also be used for protecting your website from countries that should not have access to your data.

ALLOWED_COUNTRY = "United States"

if data["country"] == ALLOWED_COUNTRY:
    print("User is allowed.")
else:
    print("Access denied. User is not in the allowed country.")

4. Handle VPN & Proxy Detection

Many users attempt to bypass geofencing using VPNs, proxies, or Tor networks. Fingerprinting API provides VPN detection to counteract this.

if data["vpn"] or data["proxy"] or data["tor"]:
    print("Access denied due to VPN/proxy usage.")
else:
    print("User access granted.")

5. Implement Geofencing in Your Web Application

Backend (Python Flask Example)

from flask import Flask, request, jsonify
from geopy.distance import geodesic

app = Flask(__name__)

API_KEY = "your_api_key"
GEOFENCE_CENTER = (40.7128, -74.0060)
GEOFENCE_RADIUS_KM = 50
ALLOWED_COUNTRY = "United States"

def get_user_location(ip):
    url = f"https://api.fingerprinting-api.com/v1/lookup?apiKey={API_KEY}&ip={ip}"
    response = requests.get(url).json()
    return response

@app.route("/check-geofence", methods=["GET"])
def check_geofence():
    user_ip = request.remote_addr
    data = get_user_location(user_ip)

    user_location = (data["latitude"], data["longitude"])
    distance = geodesic(GEOFENCE_CENTER, user_location).km

    if distance > GEOFENCE_RADIUS_KM or data["country"] != ALLOWED_COUNTRY or data["vpn"] or data["proxy"] or data["tor"]:
        return jsonify({"access": "denied"}), 403

    return jsonify({"access": "granted", "distance_km": distance})

if __name__ == "__main__":
    app.run(debug=True)

Deploy this API in your web app to enforce geofencing security.

Use Cases of Geofencing with Fingerprinting API

Fraud Prevention

  • Block transactions from unexpected regions or VPNs.

  • Prevent account takeovers from unauthorized locations.

Access Control

  • Restrict login access based on geographic regions.

  • Only allow employees to log in from designated office locations.

Geo-Targeted Offers & Personalization

  • Show promotions or content based on user’s geolocation.

  • Block users outside specific regions from accessing exclusive content.

Compliance & Legal Restrictions

  • Enforce region-specific regulations (e.g., GDPR, CCPA).

  • Restrict access to country-specific content (e.g., gambling sites, streaming platforms).

Geofencing with Fingerprinting API is a powerful alternative to traditional GPS-based solutions, offering greater reliability, VPN detection, and easy web-based integration.

By leveraging IP intelligence, device fingerprinting, and geolocation data, businesses can prevent fraud, enforce security policies, and provide location-based personalization without requiring mobile apps.

Start implementing geofencing today with Fingerprinting API and enhance your security and user experience!

Eric Tremblay

Feb 1, 2025

Latest posts

Discover other pieces of writing in our blog

Fingerprinting.API

Advanced browser fingerprinting for seamless security

© Copyright 2024. All rights reserved.

Fingerprinting.API

Advanced browser fingerprinting for seamless security

© Copyright 2024. All rights reserved.