Overview
The Geo plugin provides geocoding tools, distance queries, and map helpers for CakePHP. It lets you:
- Geocode locations and IPs and store the resulting coordinates (lat/lng) alongside your records.
- Reverse-geocode coordinates back into address data.
- Query geocoded data by distance using custom finders.
- Display dynamic Google Maps and open-source Leaflet maps.
- Render JavaScript-free static maps from multiple providers (Geoapify, Mapbox, Stadia, Google).
Installation covers packages and plugin loading. Getting started renders a map without an API key or database migration. Composer defines supported runtime versions.
How it works
The geocoding features use the willdurand/geocoder library, through optional provider packages:
- address-based geocoder providers
- IP-based geocoder providers
Reverse-geocoding support depends on the selected provider. Custom providers can implement the plugin interface.
The non-spatial distance finder supports:
- MySQL
- PostgreSQL
- SQLite built with its SQL math functions enabled (
ACOS,COS,SIN,RADIANSandPI)
The pieces
| Concept | Responsibility |
|---|---|
| Geocoder behavior | Geocodes entity address fields on save and adds distance finders to your table. |
| Geocoder class | Low-level geocoding and reverse geocoding against a configurable provider. |
| Calculator / Geo calculator | Distance math, coordinate blurring, unit conversion, and central-point calculation. |
| GeoJSON value objects | Lightweight Point, Polygon, Feature, and FeatureCollection types. |
| Map helpers | Google Maps, Leaflet, and static-map rendering for your views. |
| GeocodedAddresses cache | Optional table that reuses geocoding results to reduce repeated API calls. |
Demo
See the Sandbox examples for live demos of the map helpers and the Geocoder behavior.
Next steps
- Installation; install the plugin and load it.
- Geocoder behavior; geocode your entity data automatically.
- Map helpers; render maps in your views.