@@ -34,7 +34,7 @@ To install the package from the source tree directly, run:
34
34
35
35
Usually you would want to run this in a virtual environment.
36
36
37
- ### A simple search example
37
+ ## A simple search example
38
38
39
39
To query the Nominatim database you need to first set up a connection. This
40
40
is done by creating an Nominatim API object. This object exposes all the
@@ -88,7 +88,7 @@ implementations. The documentation itself will usually refer only to
88
88
available only for the synchronous or asynchronous version, this will be
89
89
explicitly mentioned.
90
90
91
- ### Defining which database to use
91
+ ## Defining which database to use
92
92
93
93
The [ Configuration] ( ../admin/Import.md#configuration-setup-in-env )
94
94
section explains how Nominatim is configured using the
@@ -103,7 +103,41 @@ have normally created a [project directory](../admin/Import.md#creating-the-proj
103
103
which stores the various configuration and customization files that Nominatim
104
104
needs. You may pass the location of the project directory to your
105
105
'Nominatim API class' constructor and it will read the .env file in the
106
- directory and set the configuration accordingly.
106
+ directory and set the configuration accordingly. Here is the simple search
107
+ example, using the configuration from a pre-defined project directory in
108
+ ` /srv/nominatim-project ` :
109
+
110
+ !!! example
111
+ === "NominatimAPIAsync"
112
+ ``` python
113
+ import asyncio
114
+
115
+ import nominatim_api as napi
116
+
117
+ async def search(query):
118
+ async with napi.NominatimAPIAsync('/srv/nominatim-project') as api:
119
+ return await api.search(query)
120
+
121
+ results = asyncio.run(search('Brugge'))
122
+ if not results:
123
+ print('Cannot find Brugge')
124
+ else:
125
+ print(f'Found a place at {results[0].centroid.x},{results[0].centroid.y}')
126
+ ```
127
+
128
+ === "NominatimAPI"
129
+ ``` python
130
+ import nominatim_api as napi
131
+
132
+ with napi.NominatimAPI('/srv/nominatim-project') as api:
133
+ results = api.search('Brugge')
134
+
135
+ if not results:
136
+ print('Cannot find Brugge')
137
+ else:
138
+ print(f'Found a place at {results[0].centroid.x},{results[0].centroid.y}')
139
+ ```
140
+
107
141
108
142
You may also configure Nominatim by setting environment variables.
109
143
Normally Nominatim will check the operating system environment. Lets
@@ -148,9 +182,10 @@ like this:
148
182
```
149
183
150
184
When the ` environ ` parameter is given, then only configuration variables
151
- from this dictionary will be used.
185
+ from this dictionary will be used. The operating system's environment
186
+ variables will be ignored.
152
187
153
- ### Presenting results to humans
188
+ ## Presenting results to humans
154
189
155
190
All search functions return full result objects from the database. Such a
156
191
result object contains lots of details: names, address information, OSM tags etc.
0 commit comments