Download the PHP package lounisbou/cell-location without Composer
On this page you can find all versions of the php package lounisbou/cell-location. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lounisbou/cell-location
More information about lounisbou/cell-location
Files in lounisbou/cell-location
Package cell-location
Short Description CellLocation uses API to retrieve estimation of the position of a mobile within a cell's coverage area. It can uses triangulation and enclosing circle algorithms to estimate the possible position of a device based on data from multiple cell towers.
License MIT
Informations about the package cell-location
Cell Location API Integration
This project provides a service to determine the location (latitude and longitude) based on mobile cell tower information (MCC, MNC, LAC, CellID) using various APIs, such as:
It can uses triangulation and enclosing circle algorithms to estimate the possible position of a device based on data from multiple cell towers.
Table of Contents
- Installation
- Configuration
- Usage
- Running Tests
- Future Improvements
- Contributing
- License
Installation
Prerequisites
- PHP 8.0 or higher
- Composer (dependency management)
- An API key from OpenCellID, UnwiredLabs, and/or Google Maps Geolocation API
Clone the repository
Install dependencies
Configuration
Before using the project, you need to configure environment variables for API keys. You can do this by creating a .env
file in the project root.
Example .env
file
Loading Environment Variables
The project uses the Symfony Dotenv component to load environment variables. These environment variables are automatically loaded via the Pest.php
file during tests or when running the project.
Regenerating Autoloader
Ensure your classes are autoloaded by Composer. If you add or modify any classes, make sure to run:
Usage
This project allows you to fetch the location from different services by simply providing cell tower information like MCC, MNC, LAC, and CellID.
Example Usage
Key Concepts
-
Cell Data:
CellData
stores the information of the device's interaction with the cell towers such as MNC, MCC, LAC, and CellID.
-
Cell Location:
CellLocation
objects store the physical location of the cell antenna, defined by latitude, longitude, and accuracy (distance range where the device might be relative to the tower).
-
Triangulation:
- Using data from multiple towers, the program estimates a device's position by calculating the intersection of circles defined by the cell tower locations and accuracy.
- Each circle is centered at a CellLocation's latitude and longitude, with a radius equal to the accuracy (distance to the device).
-
Intersection of Circles:
- The algorithm finds the intersection zone of the circles, calculates the centroid of the intersection, and uses the maximum distance between the centroid and the edges of the intersection zone to define the result possible position as a circle.
-
Smallest Enclosing Circle:
- The algorithm determines the smallest enclosing circle that intersects parts of all input circles. This circle's center represents the estimated device location, and the radius defines the zone of possible locations.
- Enclosing Circle Algorithm:
- This algorithm calculates the smallest circle that encloses the intersection zone of all cell coverage areas.
Center
geometric center of the intersection zone.Radius
distance from the center to the farthest point within the intersection zone.
Get CellLocation from CellData
Get triangulated CellLocation from multiple CellData
Advanced Features
Haversine Distance Calculation: Uses the Haversine formula to calculate distances between latitude and longitude points on Earth, which accounts for the Earth's curvature. Error Handling: Proper handling of cases where circles do not intersect or input data is insufficient.
Limitations
This version uses an approximate method for finding the intersection of circles. For higher precision, computational geometry algorithms can be implemented, though they may require more complex libraries. The algorithm assumes that all circles must intersect. If they don't, the program throws an error.
Services Supported
- OpenCellID: Using the
OpenCellIDService
. - UnwiredLabs: Using the
UnwiredLabsService
. - Google Geolocation API: Using the
GoogleGeolocationService
.
Running Tests
This project uses Pest for testing.
To run the tests, including those for error handling and success responses, use the following command:
Future Improvements
- Exact Circle Intersection: Implementing a more precise geometric intersection algorithm could improve the accuracy.
- RSSI Integration: While this implementation doesn't use RSSI, future improvements could involve integrating signal strength to improve location estimation.
- Kalman Filters: For real-time tracking, Kalman filters or other smoothing algorithms could be implemented to refine the estimated location based on multiple readings over time.
Contributing
If you wish to contribute to this project:
- Fork the repository.
- Create your feature branch (
git checkout -b feature/your-feature
). - Commit your changes (
git commit -m 'Add your feature'
). - Push to the branch (
git push origin feature/your-feature
). - Open a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contact
If you have any questions or run into issues, feel free to open an issue.