# GeoCoordinate filtering with python client library

**URL:** https://forum.weaviate.io/t/geocoordinate-filtering-with-python-client-library/458
**Category:** Support
**Created:** [August 4, 2023, 5:11am UTC](https://forum.weaviate.io/t/geocoordinate-filtering-with-python-client-library/458 "2023-08-04T05:11:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![khoa-cdp](https://avatars.discourse-cdn.com/v4/letter/k/b38774/32.png) [@khoa-cdp](https://forum.weaviate.io/u/khoa-cdp)
#### Post date: [August 4, 2023, 5:11am UTC](https://forum.weaviate.io/t/geocoordinate-filtering-with-python-client-library/458/1 "2023-08-04T05:11:49Z")

</div>

I’m trying to filter places by geoCoordinates but this code is getting an error

```python
where_filter = {
  'operator': 'WithinGeoRange',
  'valueGeoRange': {
    'geoCoordinates': {
      'latitude': 10.8064,
      'longitude': 106.7323,
    },
    'distance': { 'max': 2000 }
  },
  'path': ['geoLocation']
}
response = (
  client.query
  .get("Place", ["postgresId", "address"])
  .with_additional('id')
  .with_where(where_filter)
  .do()
)
response

```

The error is as follows:

```python
{'errors': [{'locations': [{'column': 83, 'line': 1}],
   'message': 'Syntax Error GraphQL request (1:83) Expected Name, found String "geoCoordinates"\n\n1: {Get{Place(where: {path: ["geoLocation"] operator: WithinGeoRange valueGeoRange: {"geoCoordinates": {"latitude": 10.8064, "longitude": 106.7323}, "distance": {"max": 2000}}} ){postgresId address _additional {id }}}}\n ^\n',
   'path': None}]}

```

I’m not sure if I’m missing anything, or does Weaviate python client not support geoLocation filtering? In the documentation that I saw, the python code uses raw query instead ([GraphQL - Conditional filters | Weaviate - vector database](https://weaviate.io/developers/weaviate/api/graphql/filters#geocoordinates-filter))

---

<div class="post-metadata">

### Author: ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)
#### Post date: [August 7, 2023, 11:30pm UTC](https://forum.weaviate.io/t/geocoordinate-filtering-with-python-client-library/458/2 "2023-08-07T23:30:26Z")

</div>

Hi @khoa-cdp ! Welcome to our community 🤗

Indeed, there seems to have something going on here. [This looks like a weaviate-python-client issue](https://github.com/weaviate/weaviate-python-client/issues). We might need to dig deep into this.

Seems like the queryBuilder is not producing the expected graphql and messing the double quotes.

The workaround, for now, is to call the raw method and query it directly, like so:

```python
get_articles_where = '''
  {
    Get {
      Place(where: {
        operator: WithinGeoRange,
        valueGeoRange: {
          geoCoordinates: {
            latitude: 17.8608, # latitude
            longitude: 41.5090 # longitude
          },
          distance: {
            max: 200000 # distance in meters
          }
        },
        path: ["geoLocation"] # property needs to be of geoLocation type.
      }) {
        postgresId
        address
        geoLocation {
          latitude
          longitude
        }
      }
    }
  }
'''
query_result = client.query.raw(get_articles_where)
print(query_result)

```

I have noticed that when using `with_where` it’s not scaping the fields correclty. We can see that happening when we `build` the query, instead of `doing` it

```python
where_filter = {
  'operator': 'WithinGeoRange',
  'valueGeoRange': {
    'geoCoordinates': {
      'latitude': 10.8064,
      'longitude': 106.7323,
    },
    'distance': { 'max': 2000 }
  },
  'path': ['geoLocation']
}
response = (
  client.query
  .get("Place", ["postgresId", "address"])
  .with_additional('id')
  .with_where(where_filter)
  .build() # replaced here from do() to build()
)
response

```

‘{Get{Place(where: {path: [“geoLocation”] operator: WithinGeoRange valueGeoRange: {“geoCoordinates”: {“latitude”: 10.8064, “longitude”: 106.7323}, “distance”: {“max”: 2000}}} ){postgresId address \_additional {id }}}}’

I will ping our team regarding this and update here with more information.

Thanks for reporting 🙂

---

<div class="post-metadata">

### Author: ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)
#### Post date: [August 16, 2023, 6:35pm UTC](https://forum.weaviate.io/t/geocoordinate-filtering-with-python-client-library/458/3 "2023-08-16T18:35:51Z")

</div>

Update! A new PR was produced to fix this issue:

> <https://github.com/weaviate/weaviate-python-client/issues/419>
>
> While using WithinGeoRange, the python client (version 3.22.1) will return an in…valid graphql.
> \[Reference thread\](https://forum.weaviate.io/t/geocoordinate-filtering-with-python-client-library/458/2)
> 
> \`\`\`python
> where\_filter = {
> 'operator': 'WithinGeoRange',
> 'valueGeoRange': {
> 'geoCoordinates': {
> 'latitude': 10.8064,
> 'longitude': 106.7323,
> },
> 'distance': { 'max': 2000 }
> },
> 'path': \['geoLocation'\]
> }
> response = (
> client.query
> .get("Place", \["postgresId", "address"\])
> .with\_additional('id')
> .with\_where(where\_filter)
> .build() # replaced here from do() to build()
> )
> response
> \`\`\`
> 
> This will output:
> \`\`\`
> {Get{Place(where: {path: \[“geoLocation”\] operator: WithinGeoRange valueGeoRange: {“geoCoordinates”: {“latitude”: 10.8064, “longitude”: 106.7323}, “distance”: {“max”: 2000}}} ){postgresId address \_additional {id }}}}
> \`\`\`
> The expected output is something similar to:
> \`\`\`
> {
> Get {
> Place(where: {
> operator: WithinGeoRange,
> valueGeoRange: {
> geoCoordinates: {
> latitude: 17.8608, # latitude
> longitude: 41.5090 # longitude
> },
> distance: {
> max: 200000 # distance in meters
> }
> },
> path: \["geoLocation"\] # property needs to be of geoLocation type.
> }) {
> postgresId
> address
> geoLocation {
> latitude
> longitude
> }
> }
> }
> }
> \`\`\`

This PR should land on upcoming versions 🙂
