Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Geodistance

Geodistance Laravel Package

jackpopp/geodistance

Laravel/PHP package to calculate geographic distances between coordinates. Supports common formulas and helpers to get miles/kilometers between points, useful for proximity search, radius filtering, and location-based features in apps.

View on GitHub
Deep Wiki
Context7

GeoDistance allows you to search for locations within a radius using latitude and longitude values with your eloquent models.

Frequently asked questions about Geodistance
How do I install jackpopp/geodistance in a Laravel project?
Run `composer require jackpopp/geodistance` to install the package. No additional Laravel service provider registration is required—it integrates directly with Eloquent. Ensure your database supports geospatial queries (e.g., MySQL SPATIAL indexes or PostgreSQL PostGIS).
Which Laravel versions does this package support?
The package is designed for Laravel 5.5+ and leverages Eloquent’s query builder. While it may work on older versions, compatibility isn’t guaranteed, and the last update was in 2018. Test thoroughly if using Laravel 6.x or 7.x.
Can I use this package with SQLite?
No, SQLite lacks native geospatial support without custom extensions. The package relies on MySQL’s SPATIAL indexes or PostgreSQL’s PostGIS. If you’re using SQLite, consider alternatives like PHP-only distance calculations (e.g., Haversine formula) or migrate to MySQL/PostgreSQL.
How do I add a radius-based query to an Eloquent model?
Use the `near()` method on your model’s query builder: `Model::near($latitude, $longitude, $radius, $unit = 'km')`. Replace `$radius` with your desired distance (e.g., 5 for 5km) and specify `unit` as `'km'` or `'mi'`. Ensure your model’s latitude/longitude columns are indexed spatially.
What database setup is required for geospatial queries?
For MySQL, add a SPATIAL index: `ALTER TABLE your_table ADD SPATIAL INDEX (latitude, longitude)`. For PostgreSQL, enable PostGIS (`CREATE EXTENSION postgis`) and add a `GEOGRAPHY(POINT, 4326)` column. SQLite is unsupported without third-party extensions.
Will this package work in production with high traffic?
Geospatial queries can be resource-intensive. Test under load to monitor performance, especially with large radius searches. Database-native functions (e.g., MySQL’s `ST_Distance`) are faster than PHP-based calculations. Consider caching frequent queries or optimizing indexes.
Are there alternatives to jackpopp/geodistance for Laravel?
Yes, consider `spatie/laravel-geolocation` (actively maintained) or `torann/laravel-geocoder` for geocoding and distance calculations. If you need a lightweight solution, `vinkla/hashid` (for encoding) + custom Haversine logic is another option, though it lacks Eloquent integration.
How do I handle invalid or missing latitude/longitude values?
The package doesn’t include built-in validation, so you’ll need to filter or default values manually. For example, add a scope to your model: `public function scopeValidCoordinates($query) { return $query->whereNotNull('latitude')->whereNotNull('longitude'); }`. Test edge cases like NULL or out-of-bounds values.
Can I use this package for global applications (e.g., queries across timezones or antimeridians)?
The package uses basic distance formulas, which may introduce errors near the antimeridian or poles. For global accuracy, rely on database-native geospatial functions (e.g., PostgreSQL’s PostGIS) or consider a dedicated geospatial database like MongoDB with GeoJSON support.
Is jackpopp/geodistance still maintained? Should I use it for new projects?
The package hasn’t been updated since 2018 and lacks active maintenance. For new projects, evaluate alternatives like `spatie/laravel-geolocation` or `torann/laravel-geocoder`, which are more actively developed. If you proceed, plan for potential future migration.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity