# Trying to center a map in canvas

**URL:** https://discuss.elastic.co/t/trying-to-center-a-map-in-canvas/224489
**Category:** Kibana
**Created:** [March 20, 2020, 9:03pm UTC](https://discuss.elastic.co/t/trying-to-center-a-map-in-canvas/224489 "2020-03-20T21:03:10Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![flaviogoncalves](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flaviogoncalves/32/60995_2.png) [@flaviogoncalves](https://discuss.elastic.co/u/flaviogoncalves)
#### Post date: [March 20, 2020, 9:03pm UTC](https://discuss.elastic.co/t/trying-to-center-a-map-in-canvas/224489/1 "2020-03-20T21:03:10Z")

</div>

I´m trying to centralize a map base in a chosen city. I´ve succesfully create two filters state and city to filter a map. After applying the filter the map displays only the city however I can´t define the latitude and longitude automatically and it is very hard to find the city. I have latitude and longitude in the same index as the map (mapa\_cidades\_brasil), but I´m unable to use the data from the table to centralize the map. I tried:

```auto
filters group="CIDADE" ungrouped=true
| esdocs index="mapa_brasil_cidades*"
fields="uf.keyword, nome.keyword, populacao, tx_wifi, vel_med, latitude, longitude" sort=", asc"
| alterColumn column="latitude" type="number"
| alterColumn column="longitude" type="number"
| savedMap id="4cc6bec0-5e41-11ea-87b6-cb7f060ff65e" center={mapCenter lat="latitude" lon="longitude" zoom=7.16} timerange={timerange from="now-15m" to="now"}
| render as="debug"

```

However, I can´t set latitude and longitude (center of the city) as parameters in the map.

Anyone able to help?

---

<div class="post-metadata">

### Author: ![lukeelmers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukeelmers/32/35230_2.png) [@lukeelmers](https://discuss.elastic.co/u/lukeelmers)
#### Post date: [March 21, 2020, 2:54am UTC](https://discuss.elastic.co/t/trying-to-center-a-map-in-canvas/224489/2 "2020-03-21T02:54:15Z")

</div>

Hi @flaviogoncalves,

It looks like you might be missing [the `getCell` function](https://www.elastic.co/guide/en/kibana/current/canvas-function-reference.html#getCell_fn) to pass the relevant input to `mapCenter`. Currently you have:

```auto
mapCenter lat="latitude" lon="longitude" zoom=7.16

```

This is passing the literal string values `"latitude"` and `"longitude"` as arguments to the `mapCenter` function. Most likely what you are trying to do is something like this:

```auto
mapCenter lat={getCell column="latitude"} lon={getCell column="longitude"} zoom=7.16

```

This will look up the columns from the tabular data provided as context to the function.

Does this work for you? Let me know!

Cheers -

Luke

---

<div class="post-metadata">

### Author: ![flaviogoncalves](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flaviogoncalves/32/60995_2.png) [@flaviogoncalves](https://discuss.elastic.co/u/flaviogoncalves)
#### Post date: [March 21, 2020, 11:40am UTC](https://discuss.elastic.co/t/trying-to-center-a-map-in-canvas/224489/3 "2020-03-21T11:40:52Z")

</div>

> [@lukeelmers](#):
>
> {getCell column="latitude"}

Thanks for your reply,

I´ve tried but got the following error:

[savedMap] \> Cannot read property 'map' of undefined

The easiest way would be to have a feature in the map to autocenter. Get the lowest and highest latitude and longitude of the objects selected to center and zoom accordingly.

---

<div class="post-metadata">

### Author: ![flaviogoncalves](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flaviogoncalves/32/60995_2.png) [@flaviogoncalves](https://discuss.elastic.co/u/flaviogoncalves)
#### Post date: [March 24, 2020, 12:20am UTC](https://discuss.elastic.co/t/trying-to-center-a-map-in-canvas/224489/4 "2020-03-24T00:20:40Z")

</div>

Another interesting aspect is the coordinates adjust in real time whenever you move the map.

---

<div class="post-metadata">

### Author: ![lukeelmers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukeelmers/32/35230_2.png) [@lukeelmers](https://discuss.elastic.co/u/lukeelmers)
#### Post date: [March 24, 2020, 8:34pm UTC](https://discuss.elastic.co/t/trying-to-center-a-map-in-canvas/224489/5 "2020-03-24T20:34:23Z")

</div>

> The easiest way would be to have a feature in the map to autocenter. Get the lowest and highest latitude and longitude of the objects selected to center and zoom accordingly.

Yeah I agree, that'd be a helpful feature. I was going to point you to [an enhancement request for maps to add this in Github](https://github.com/elastic/kibana/issues/53831) but I was happy to discover you have already joined the conversation there 😄

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [April 21, 2020, 8:34pm UTC](https://discuss.elastic.co/t/trying-to-center-a-map-in-canvas/224489/6 "2020-04-21T20:34:30Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
