Right now this extension provides the following features
- Get the user position based on the users IP address
- Geocoding: Get position by address string
- Add field "Geoselect" for usage in TYPO3 FormFactory classes
All features are implemented as TYPO3 services so there is a well defined fallback behaviour and the possibility for other developers to add their own services.
Start by getting the instance of the GeoUtility class. You can do that multiple times - it's a singleton so you will only get the same instance every time.
// Get location for current user IP
GeneralUtility::makeInstance(GeoUtility::class)->getGeolocation();
// Get location for a specific IP
GeneralUtility::makeInstance(GeoUtility::class)->getGeolocation('127.0.0.1');
- Tollwerk\TwGeo\Service\Geolocation\GeoiplookupService
- Uses the geoiplookup server command
- Tollwerk\TwGeo\Service\Geolocation\PhpGeoIPService
- Uses the PHP GeoIPService
GeneralUtility::makeInstance(GeoUtility::class)->geocode('Some street, SomeCity');
- Tollwerk\TwGeo\Service\Geocoding\OpenStreetMapService
- Uses the OSM Nominatim web API. See https://wiki.openstreetmap.org/wiki/Nominatim
- Tollwerk\TwGeo\Service\Geocoding\GoogleMapsService
- Uses the Google Maps API. See https://developers.google.com/maps/documentation/geocoding/intro
Usable inside FormFactory classes
/** @var TYPO3\CMS\Form\Domain\Model\FormElements\Page $page */
$geoselectField = $page->createElement('yourFieldName','Geoselect');
A static google map
/** @var TYPO3\CMS\Form\Domain\Model\FormElements\Page $page */
$geoselectField = $page->createElement('yourFieldName','StaticMap');
// See \Tollwerk\TwGeo\Domain\Model\FormElementy->properties for more
$geoselectField->setProperty('latitude', 0);
$geoselectField->setProperty('longitude', 0);
In TYPO3 backend go to Admin Tools > Settings > Extension Configuration > tw_geo.
There you can set debug IP adresses for which fake values should be returned. Especially useful when devloping on a local machine where no geolocation is possible.
There is also a frontend plugin available you can add to any page to test different features of this extension.