Getting Places Using Multiple Filters
You can find places using a combination of different filters simply by specifying them as parameters in the request. Currently, the following filters are available:
countryIds | Only places in these countries (comma-delimited country codes or wikiDataIds) |
excludedCountryIds | Only places NOT in these countries (comma-delimited country codes or wikiDataIds) |
minPopulation | Only places having at least this population |
maxPopulation | Only places having less than or equal to this population |
namePrefix | Only places whose names start with this prefix |
location | Only places near this location. Latitude/longitude in ISO-6709 format: ±DD.DDDD±DDD.DDDD (Note: This param is broken out into separate fields for GraphQL. See GraphQL Schema docs for details.) |
timeZoneIds | Only places in these time-zones (comma-delimited time-zone IDs). Note that you should use the IDs returned by the GeoDB service, as they correctly encode the '/' character. (Alternatively simply replace '/' with a double-underscore: '__'.) |
Note that some parameters are logically mutually exclusive of each other, and if your request includes them simultaneously, you will quickly be shown the error of your evil ways via a descriptive error response. These are:
- countryIds, excludedCountryIds You cannot both include and exclude countries at the same time.
- location, (countryIds | excludedCountryIds | timeZoneIds) You cannot include or exclude countries or constrain by time-zones when filtering by location.
Below we find cities starting with 'san', having a minimum population of 100000, and only in the US or Spain.
GraphQL
curl --request POST \ --url https://geodb-cities-graphql.p.rapidapi.com/ \ --header 'content-type: application/json' \ --header 'x-rapidapi-host: geodb-cities-graphql.p.rapidapi.com' \ --header 'x-rapidapi-key: YOUR_API_KEY' \ --data '{"query":"QUERY"}'
Where QUERY:
{ populatedPlaces(namePrefix:"san", countryIds:["US","ES"], minPopulation:100000, first:10) { totalCount pageInfo{ startCursor endCursor hasNextPage } edges { node { id name country { name } } } } }
REST
curl --get --include 'https://wft-geo-db.p.rapidapi.com/v1/geo/places?namePrefix=san&minPopulation=100000&countryIds=US,ES&offset=0&limit=10' \ -H 'x-rapidapi-key: YOUR_API_KEY' \ -H 'x-rapidapi-host: wft-geo-db.p.rapidapi.com'