Geocoding is the process of matching an address or other text to its corresponding geographic coordinates.
In the simplest search, you can provide only one parameter, the text you want to match in any part of the location details. To do this, build a query where the text parameter is set to the item you want to find.
For example, if you want to find Paris, here’s what you’d need to append to the base URL of the service, api.jawg.io/places.
Clicking the link above will open a file containing the best matching results for the text Paris. You will notice the data is in a computer-friendly format called GeoJSON, which may be hard for humans to read in some browsers.
You can install a plug-in for your browser to display JSON in a more formatted manner. You can search the web store for your browser to find and install applicable products.
Note that the results are spread out throughout the world because you have not given your current location or provided any other geographic context in which to search.
With the text parameter, your search is composed of all the items in one string. With structured geocoding (http://api.jawg.io/places/v1/search/structured/), you can search for individual components of a location.
Structured geocoding also supports the other parameters from search, allowing you to filter and prioritize your results.
For more information on how to search this way, see Structured geocoding.
By default, Pelias results up to 10 places, unless otherwise specified. If you want a different number of results, set the size parameter to the desired number. This example shows returning only the first result.
If you are looking for places in a particular region, or country, or only want to look in the immediate vicinity of a user with a known location, you can narrow your search to an area. There are different ways of including a region in your query. Pelias supports three types: country, rectangle, and circle.
If you try the same search request with different country codes, the results change to show Paris locations within this region.
To specify the boundary using a rectangle, you need latitude, longitude coordinates for two diagonals of the bounding box (the minimum and the maximum latitude, longitude).
Tip: You can look up a bounding box for a known region with this web tool.
Sometimes you don’t have a rectangle to work with, but rather you have a point on earth—for example, your location coordinates—and a maximum distance within which acceptable results can be located.
In this example, you want to find all Paris locations within a 300-kilometer radius of a location in Ontario, Canada. This time, you can use the boundary.circle.* parameter group, where boundary.circle.lat and boundary.circle.lon is your location in Ontario and boundary.circle.radius is the acceptable distance from that location. Note that the boundary.circle.radius parameter is always specified in kilometers.
If you’re going to try using multiple boundary types in a single search request, be aware that the results will come from the intersection of all the boundaries. So, if you provide regions that don’t overlap, you’ll be looking at an empty set of results.
Many use cases call for the ability to promote nearby results to the top of the list, while still allowing important matches from farther away to be visible. Pelias allows you to prioritize results within geographic boundaries, including around a point, within a country, or within a region.
By specifying a focus.point, nearby places will be scored higher depending on how close they are to the focus.point so that places with higher scores will appear higher in the results list. The effect of this scoring boost diminishes to zero after 100 kilometers away from the focus.point. After all the nearby results have been found, additional results will come from the rest of the world, without any further location-based prioritization.
To find Paris again, but this time near a specific coordinate location (representing the Sydney Opera House) in Sydney, Australia, use focus.point.
Looking at the results, you can see that the few locations closer to this location show up at the top of the list, sorted by distance. You also still get back a significant amount of remote locations, for a well balanced mix. Because you provided a focus point, Pelias can compute distance from that point for each resulting feature.
Now that you have seen how to use boundary and focus to narrow and sort your results, you can examine a few scenarios where they work well together.
Going back to the Paris search you conducted with a focus around a point in Hell’s Kitchen, the results came back from distant parts of the world, as expected. But say you wanted to only see results from the country in which your focus point lies. You can combine that same focus point in Hell’s Kitchen with the country boundary of United States like this.
The results below look different from the ones you saw before with only a focus point specified. These results are all from within Australia. You’ll note the closest results show up at the top of the list, which is helped by the focus parameter.
If you are looking for the nearest Paris locations, and are willing to travel no farther than 500 kilometers from your current location, you likely would want the results to be sorted by distance from current location to make your selection process easier. You can get this behavior by using focus.point in combination with boundary.circle.*. You can use the focus.point.* values as the boundary.circle.lat and boundary.circle.lon, and add the required boundary.circle.radius value in kilometers.
Pelias brings together data from multiple open sources and combines a variety of place types into a single database, allowing you options for selecting the dataset you want to search.
If you use the sources parameter, you can choose which of these data sources to include in your search. So if you’re only interested in finding a Paris in data from OpenAddresses, for example, you can build a query specifying that data source.
If you wanted to combine several data sources together, set sources to a comma separated list of desired source names. Note that the order of the comma separated values does not impact sorting order of the results; they are still sorted based on the linguistic match quality to text and distance from focus, if you specified one.
Each of these data sources has properties, licenses, and strengths. You can learn more about the data sources for Pelias.