Skip to content
  1. Extras
  2. GeoLocation2
  3. Quick start

Quick start

1. Settings

In System → System Settings → geolocation2 set:

KeyRecommended for start
geolocation2_detect_methodsxgeo — detect by IP on first visit
geolocation2_debug0 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.

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

  1. Open the site in a private window.
  2. Modal should offer a city (SxGeo) or a city list.
  3. After selection the city is stored in $_SESSION['gl2'].
  4. GET /assets/components/geolocation2/action.php?action=state (with X-Requested-With) returns JSON with state, confirmed and 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.