
Quick start
1. Settings
In System → System Settings → geolocation2 set:
| Key | Recommended for start |
|---|---|
geolocation2_detect_method | sxgeo — detect by IP on first visit |
geolocation2_debug | 0 in production, 1 while debugging |
Details: System settings.
2. Site template
In <head> or before </body> add initialization (CSS/JS and Bootstrap 5 if not already on the page):
fenom
{'!GeoLocation2Initialize' | snippet}modx
[[!GeoLocation2Initialize]]Parameters loadBootstrap, loadCss, loadJs — see GeoLocation2Initialize.
3. Modal and current city
In header or footer:
fenom
{'!GeoLocation2Current' | snippet : [
'tpl' => 'tpl.GeoLocation2.current'
]}
{'!GeoLocation2Modal' | snippet}modx
[[!GeoLocation2Current? &tpl=`tpl.GeoLocation2.current`]]
[[!GeoLocation2Modal]]Chunk tpl.GeoLocation2.current ships with the package. Use data-gl2-open="1" on the button to open the modal.
4. Verify
- Open the site in a private window.
- Modal should offer a city (SxGeo) or a city list.
- After selection the city is stored in
$_SESSION['gl2']. GET /assets/components/geolocation2/action.php?action=state(withX-Requested-With) returns JSON withstate,confirmedand session fields.
5. City data
If you filled gl_data in the manager:
fenom
{'!GeoLocation2Data' | snippet : [
'forCurrent' => 1,
'tpl' => 'tpl.GeoLocation2.data.current'
]}modx
[[!GeoLocation2Data? &forCurrent=`1` &tpl=`tpl.GeoLocation2.data.current`]]Next: Integration, Web API, FAQ.
