Decentralized Geospatial Data Management Using the Cyberfly SDK
Introduction
Managing geospatial data has always been a challenge, especially with centralized systems prone to single points of failure and data sovereignty issues. Enter Cyberfly SDK — a powerful JavaScript toolkit designed for decentralized geospatial data storage and retrieval. Built on Cyberfly Node ensures secure and scalable geospatial data management without relying on a central authority.
This article walks you through how to create a decentralized database, store geospatial data, and retrieve it using Cyberfly SDK.
Setting Up Cyberfly SDK
Before we dive into geospatial operations, let’s set up the Cyberfly SDK and create a database. First, install the SDK if you haven’t already:
npm install @cyberfly-io/client
Then, initialize it in your project:
import { CyberflySDK } from "@cyberfly-io/client";
const sdk = new CyberflySDK('https://node.cyberfly.io');
Creating a Decentralized Database
To store geospatial data, we first need a database. Cyberfly uses OrbitDB for decentralized storage, ensuring seamless synchronization across nodes.
const keyPair = sdk.generateKeyPair();
console.log('Generated Key Pair:', keyPair);
// Or use an existing secret key
sdk.setSecretKey(keyPair.secretKey);
// Create a new database
const dbCreation = await sdk.createDatabase({
name: 'test-db'
});
console.log('Database created:', dbCreation.dbaddr);
At this point, we have a decentralized database ready to store geospatial data.
Storing Geospatial Data
Now, let’s store some geospatial data, such as the coordinates of San Francisco.
const geoUpdate = await sdk.updateGEO({
dbaddr: dbCreation.dbaddr,
data: {
locationLabel: "Cities",
latitude: 37.7749,
longitude: -122.4194,
member: 'san-francisco'
},
});
console.log('Geospatial data stored:', geoUpdate);
This securely stores the location data in the decentralized database, ensuring tamper-proof storage and network-wide availability.
Retrieving Geospatial Data
Cyberfly SDK provides powerful query methods for retrieving geospatial data efficiently.
Searching by Coordinates
Retrieve all members within a specific radius of given coordinates:
const locationLabel = "Cities";
const radius = 1000000;
const lon = 1.5;
const lat = 1.5;
const unit = 'km';
const result_by_coords = await sdk.geoSearch(
dbCreation.dbaddr, locationLabel, lon, lat, radius, unit
);
console.log('Search by coordinates:', result_by_coords);
Searching by Member
Retrieve members near another member’s location:
const member = "san-francisco";
const result_by_member = await sdk.geoSearchWith(
dbCreation.dbaddr, locationLabel, member, radius, unit
);
console.log('Search by member:', result_by_member);
Getting Distance Between Two Members
Find the distance between two members:
const distance = await sdk.getDistance(
dbCreation.dbaddr, locationLabel, "san-francisco", "los-angeles", "km"
);
console.log('Distance:', distance, 'km');
Fetching Exact Position
Get the exact coordinates of a specific member:
const position = await sdk.getPosition(
dbCreation.dbaddr, locationLabel, "san-francisco"
);
console.log('San Francisco Position:', position);
Retrieving GeoHash
For efficient geospatial indexing, you can obtain a geohash for a member’s location:
const hash = await sdk.getGeoHash(
dbCreation.dbaddr, locationLabel, "san-francisco"
);
console.log('GeoHash:', hash);
Why Use Cyberfly for Geospatial Data?
- Decentralization — No central server means no single point of failure.
- Data Integrity — Cryptographically signed data ensure authenticity.
- Real-Time Updates — WebSocket-based subscriptions allow instant data updates.
- Scalability — Powered by OrbitDB and Libp2p, Cyberfly can sync data across thousands of nodes.
Conclusion
Cyberfly SDK makes decentralized geospatial data management seamless and efficient. Whether you’re building location-based dApps, IoT networks, or mapping services, Cyberfly provides the flexibility and security needed for next-gen applications.
Try it out today, and let’s decentralize the map!