Introduction
The geo-intel-offline library has been a game-changer for developers who need offline geolocation intelligence without API dependencies. With the latest releases (v1.5.0 for Python and v1.2.0 for JavaScript), we’re introducing four powerful new features that extend the library far beyond simple geocoding.
If you’re building location-aware applications, IoT devices, edge computing solutions, or any system that needs to work offline, these updates are designed for you.
What’s New: Four Major Features
1. Distance Calculation
Calculate distances between any two locations with automatic unit detection and multiple algorithms.
Why This Matters:
Traditional distance calculation libraries require you to:
- Manually specify units (km vs miles)
- Choose algorithms yourself
- Handle different input formats separately
geo-intel-offline does all of this automatically.
Python Example
from geo_intel_offline import calculate_distance
result = calculate_distance([40.7128, -74.0060], [34.0522, -118.2437])
print(f"{result.distance:.2f} {result.unit}")
result = calculate_distance("United States", "Canada")
print(f"{result.distance:.2f} {result.unit}")
result = calculate_distance("US", "CA", unit='km', method='vincenty')
print(f"{result.distance:.2f} km")
result_haversine = calculate_distance("NYC", "LA", method='haversine')
result_vincenty = calculate_distance("NYC", "LA", method='vincenty')
result_cosine = calculate_distance("NYC", "LA", method='cosine')
JavaScript Example
const { calculateDistance } = require('geo-intel-offline');
const result = calculateDistance(
[40.7128, -74.0060],
[34.0522, -118.2437]
);
console.log(`${result.distance.toFixed(2)} ${result.unit}`);
const usToCanada = calculateDistance("United States", "Canada");
console.log(`${usToCanada.distance.toFixed(2)} ${usToCanada.unit}`);
const resultKm = calculateDistance("US", "CA", {
unit: 'km',
method: 'vincenty'
});
console.log(`${resultKm.distance.toFixed(2)} km`);
Key Features:
- Smart Unit Detection: Automatically uses miles for US, GB, LR, MM; kilometers for others
- Three Algorithms: Haversine (fast), Vincenty (most accurate), Spherical Law of Cosines (balanced)
- Flexible Inputs: Coordinates, country names, ISO codes, or continent names
- Automatic Method Selection: Chooses optimal algorithm based on distance
2. Geo-fencing
Monitor location proximity with state tracking and configurable alerts, perfect for location-based services, IoT devices, and proximity applications.
Why This Matters:
Most geo-fencing libraries only tell you if you’re inside or outside. geo-intel-offline tracks state transitions (OUTSIDE → APPROACHING → INSIDE → LEAVING) and provides configurable alerts.
Python Example
from geo_intel_offline import check_geofence, GeofenceMonitor, GeofenceConfig
result = check_geofence(
current_location=(40.7128, -74.0060),
destination=(40.7130, -74.0060),
radius=1000,
radius_unit='m'
)
print(f"Inside: {result.is_inside}")
print(f"State: {result.state}")
print(f"Distance: {result.distance:.2f} {result.distance_unit}")
config = GeofenceConfig(
radius=1000,
radius_unit='m',
approaching_threshold_percent=10.0
)
monitor = GeofenceMonitor(config)
result = monitor.check(
current_location=(40.7128, -74.0060),
destination=(40.7130, -74.0060)
)
if result.alert:
print(f"Alert: {result.alert.type}")
print(f"Previous state: {result.previous_state}")
print(f"Current state: {result.state}")
delivery_monitor = GeofenceMonitor(GeofenceConfig(radius=500, radius_unit='m'))
delivery_location = (40.7130, -74.0060)
result1 = delivery_monitor.check((40.7200, -74.0100), delivery_location)
result2 = delivery_monitor.check((40.7135, -74.0065), delivery_location)
result3 = delivery_monitor.check((40.7140, -74.0070), delivery_location)
JavaScript Example
const { checkGeofence, GeofenceMonitor, GeofenceConfig } = require('geo-intel-offline');
const result = checkGeofence(
[40.7128, -74.0060],
[40.7130, -74.0060],
{
radius: 1000,
radiusUnit: 'm'
}
);
console.log(`Inside: ${result.isInside}`);
console.log(`State: ${result.state}`);
console.log(`Distance: ${result.distance.toFixed(2)} ${result.distanceUnit}`);
const config = new GeofenceConfig({
radius: 1000,
radiusUnit: 'm',
approachingThresholdPercent: 10.0
});
const monitor = new GeofenceMonitor(config);
const checkResult = monitor.check(
[40.7128, -74.0060],
[40.7130, -74.0060]
);
if (checkResult.alert) {
console.log(`Alert: ${checkResult.alert.type}`);
console.log(`Previous: ${checkResult.previousState}`);
console.log(`Current: ${checkResult.state}`);
}
Key Features:
- State Tracking: OUTSIDE, APPROACHING, INSIDE, LEAVING
- Configurable Alerts: Reached, Entered, Exited, Approaching, Leaving
- Dual APIs: Stateless
check_geofence() for one-off checks, GeofenceMonitor for tracking - Multiple Units: Meters, kilometers, and miles
3. Random Coordinates by Region
Generate random coordinates within countries or continents with point-in-polygon validation, perfect for testing, data generation, and simulation.
Why This Matters:
Generating random coordinates sounds simple, but ensuring they’re actually within a country’s boundaries is complex. geo-intel-offline uses point-in-polygon validation to guarantee all coordinates are valid.
Python Example
from geo_intel_offline import generate_random_coordinates_by_region
result = generate_random_coordinates_by_region("United States", count=10, seed=42)
for lat, lon in result.coordinates:
print(f"({lat:.4f}, {lon:.4f})")
europe_coords = generate_random_coordinates_by_region("Europe", count=5, seed=42)
for lat, lon in europe_coords.coordinates:
print(f"Europe: ({lat:.4f}, {lon:.4f})")
us_coords = generate_random_coordinates_by_region("US", count=20, seed=123)
print(f"Generated {len(us_coords.coordinates)} valid US coordinates")
test_coordinates = generate_random_coordinates_by_region(
"United States",
count=1000,
seed=42
)
for coord in test_coordinates.coordinates:
process_location(coord)
JavaScript Example
const { generateRandomCoordinatesByRegion } = require('geo-intel-offline');
const result = generateRandomCoordinatesByRegion("United States", {
count: 10,
seed: 42
});
result.coordinates.forEach(([lat, lon]) => {
console.log(`(${lat.toFixed(4)}, ${lon.toFixed(4)})`);
});
const europeCoords = generateRandomCoordinatesByRegion("Europe", {
count: 5,
seed: 42
});
const usCoords = generateRandomCoordinatesByRegion("US", {
count: 20,
seed: 123
});
console.log(`Generated ${usCoords.coordinates.length} valid US coordinates`);
Key Features:
- Region Support: Countries and continents
- Point-in-Polygon Validation: Ensures all coordinates are actually within the region
- Reproducible: Seed support for deterministic generation
- Efficient: Rejection sampling with bounding box optimization
4. Random Coordinates by Area
Generate random coordinates within a circular area with uniform distribution, ideal for location-based games, proximity testing, and area sampling.
Python Example
from geo_intel_offline import generate_random_coordinates_by_area
result = generate_random_coordinates_by_area(
center=(40.7128, -74.0060),
radius=10,
count=5,
radius_unit='km',
seed=42
)
for lat, lon in result.coordinates:
print(f"({lat:.4f}, {lon:.4f})")
result_miles = generate_random_coordinates_by_area(
center=(40.7128, -74.0060),
radius=5,
count=10,
radius_unit='mile',
seed=42
)
service_center = (40.7128, -74.0060)
service_area = generate_random_coordinates_by_area(
center=service_center,
radius=25,
count=100,
radius_unit='km',
seed=42
)
for customer_location in service_area.coordinates:
check_service_availability(customer_location)
JavaScript Example
const { generateRandomCoordinatesByArea } = require('geo-intel-offline');
const result = generateRandomCoordinatesByArea(
[40.7128, -74.0060],
{
radius: 10,
count: 5,
radiusUnit: 'km',
seed: 42
}
);
result.coordinates.forEach(([lat, lon]) => {
console.log(`(${lat.toFixed(4)}, ${lon.toFixed(4)})`);
});
const resultMiles = generateRandomCoordinatesByArea(
[40.7128, -74.0060],
{
radius: 5,
count: 10,
radiusUnit: 'mile',
seed: 42
}
);
Key Features:
- Circular Areas: Define center and radius
- Uniform Distribution: Properly distributed points within the circle
- Multiple Units: Meters, kilometers, miles, or degrees
- Reproducible: Seed support
Why geo-intel-offline is Better Than Other Libraries
1. True Offline Operation
Most geolocation libraries require API calls:
import geopy
from geopy.distance import distance
result = distance((40.7128, -74.0060), (34.0522, -118.2437))
from geo_intel_offline import calculate_distance
result = calculate_distance([40.7128, -74.0060], [34.0522, -118.2437])
Benefits:
- No API keys required
- No rate limits
- No internet dependency
- Perfect for IoT and edge devices
- Lower latency (no network calls)
2. Smart Defaults and Auto-Detection
Other libraries make you specify everything manually:
import geopy
from geopy.distance import geodesic
distance_km = geodesic((40.7128, -74.0060), (34.0522, -118.2437)).kilometers
distance_miles = distance_km * 0.621371
from geo_intel_offline import calculate_distance
result = calculate_distance("United States", "Canada")
Benefits:
- Less code to write
- Fewer errors
- Context-aware defaults
- Better developer experience
3. Comprehensive Feature Set
Most libraries focus on one thing:
| Feature | geopy | geolib | geo-intel-offline |
|---|
| Distance Calculation | ✅ | ✅ | ✅ |
| Geo-fencing | ❌ | ❌ | ✅ |
| Random Coordinates | ❌ | ❌ | ✅ |
| Offline Operation | ❌ | Partial | ✅ |
| Country Resolution | ❌ | ❌ | ✅ |
| Smart Unit Detection | ❌ | ❌ | ✅ |
| State Tracking | ❌ | ❌ | ✅ |
geo-intel-offline provides everything you need in one package.
4. Performance
geo-intel-offline is optimized for performance:
- Distance Calculation: < 0.1ms per calculation
- Geo-fencing Check: < 0.5ms per check
- Random Coordinate Generation: ~1-5ms per coordinate
- Memory Footprint: ~15MB total (all country data included)
Compare this to API-based solutions:
- Network latency: 50-200ms per call
- Rate limits: Often 1000 requests/day
- Cost: $0.005-0.05 per request
5. Cross-Language Consistency
Both Python and JavaScript versions have the same API design:
from geo_intel_offline import calculate_distance
result = calculate_distance("US", "CA")
const { calculateDistance } = require('geo-intel-offline');
const result = calculateDistance("US", "CA");
Same features, same behavior, same results, just different syntax.
6. Production-Ready
- ✅ 100% backward compatible: All existing code continues to work
- ✅ Comprehensive testing: 95+ new feature tests, 100% pass rate
- ✅ Type safety: Full TypeScript definitions (JavaScript)
- ✅ Well documented: Comprehensive README with examples
- ✅ MIT License: Free for commercial use
Real-World Use Cases
1. IoT Device Tracking
from geo_intel_offline import GeofenceMonitor, GeofenceConfig
config = GeofenceConfig(radius=100, radius_unit='m')
monitor = GeofenceMonitor(config)
device_location = get_device_gps()
home_location = (40.7128, -74.0060)
result = monitor.check(device_location, home_location)
if result.alert and result.alert.type == "ENTERED":
send_notification("Device arrived home")
elif result.alert and result.alert.type == "LEAVING":
send_notification("Device leaving home")
2. Delivery Route Optimization
from geo_intel_offline import calculate_distance, generate_random_coordinates_by_area
delivery_center = (40.7128, -74.0060)
delivery_locations = generate_random_coordinates_by_area(
center=delivery_center,
radius=25,
count=50,
radius_unit='km'
)
distances = []
for location in delivery_locations.coordinates:
dist = calculate_distance(delivery_center, location)
distances.append((location, dist.distance))
distances.sort(key=lambda x: x[1])
3. Load Testing Location Services
from geo_intel_offline import generate_random_coordinates_by_region
test_coordinates = generate_random_coordinates_by_region(
"United States",
count=10000,
seed=42
)
for coord in test_coordinates.coordinates:
test_geocoding_api(coord)
4. Location-Based Game Development
const { generateRandomCoordinatesByArea, checkGeofence } = require('geo-intel-offline');
const playerLocation = [40.7128, -74.0060];
const treasures = generateRandomCoordinatesByArea(playerLocation, {
radius: 5,
count: 10,
radiusUnit: 'km',
seed: Date.now()
});
treasures.coordinates.forEach(treasure => {
const result = checkGeofence(playerLocation, treasure, {
radius: 50,
radiusUnit: 'm'
});
if (result.isInside) {
collectTreasure(treasure);
}
});
Performance Benchmarks
Distance Calculation
| Operation | geo-intel-offline | geopy (API) | Speedup |
|---|
| Single calculation | 0.1ms | 50-200ms | 500-2000x |
| Batch (1000) | 100ms | 50-200s | 500-2000x |
Geo-fencing
| Operation | geo-intel-offline | Custom Implementation |
|---|
| Single check | 0.5ms | 2-5ms |
| State tracking | Built-in | Manual coding |
Random Coordinates
| Operation | geo-intel-offline | Manual Implementation |
|---|
| 100 coordinates | 100-500ms | Hours of coding |
Installation
Python
pip install geo-intel-offline==1.5.0
JavaScript/Node.js
npm install geo-intel-offline@1.2.0
Browser (JavaScript)
<script src="https://unpkg.com/geo-intel-offline@1.2.0/dist/geo-intel-offline.min.js"></script>
Migration Guide
If you’re using a previous version, don’t worry, everything is 100% backward compatible. Your existing code will continue to work without any changes.
New features are additive:
from geo_intel_offline import resolve_country
country = resolve_country(40.7128, -74.0060)
from geo_intel_offline import calculate_distance, check_geofence
distance = calculate_distance("US", "CA")
What’s Next?
We’re constantly improving geo-intel-offline. Upcoming features include:
- Elevation data: Get altitude information
- Time zone calculations: More detailed timezone support
- Route planning: Multi-point route optimization
- Geohash utilities: Enhanced geohash support
Conclusion
The geo-intel-offline v1.5.0 (Python) and v1.2.0 (JavaScript) releases represent a significant leap forward in offline geolocation intelligence. With distance calculation, geo-fencing, and random coordinate generation, you now have everything you need to build sophisticated location-aware applications that work completely offline.
Key Takeaways:
- Four major new features extend the library beyond geocoding
- Smart defaults reduce code complexity
- True offline operation eliminates API dependencies
- Production-ready with comprehensive testing
- Cross-language consistency between Python and JavaScript
Whether you’re building IoT devices, edge computing solutions, or web applications that need to work offline, geo-intel-offline provides the tools you need.
Resources
Made with ❤️ by Rakesh Ranjan Jena
For questions, issues, or contributions, please visit the GitHub repositories linked above.