# How does lookat API function actually work?

**URL:** <https://forum.mapillary.com/t/how-does-lookat-api-function-actually-work/1645>\
**Category:** Mobile apps\
**Created:** [April 26, 2018, 8:05am UTC](https://forum.mapillary.com/t/how-does-lookat-api-function-actually-work/1645 "2018-04-26T08:05:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![momut1](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.mapillary.com/momut1/32/1094_2.png) [@momut1](https://forum.mapillary.com/u/momut1)\
**Post date:** [April 26, 2018, 8:05am UTC](https://forum.mapillary.com/t/how-does-lookat-api-function-actually-work/1645/1 "2018-04-26T08:05:18Z")

</div>

Hey Map-heads,

This might be a question for the support team as well, but… here goes nothing:  
I was searching through the documentation, but couldn’t find a decisive answer for this question. I am interested to know exactly what sequence of operations does the `lookat` API function use to decide whether an image is indeed looking at a coordinate point. The answer I am looking for would ideally include a commented code snippet.

Much obliged,

Momo

---

<div class="post-metadata">

**Author:** ![tao](https://avatars.discourse-cdn.com/v4/letter/t/f9ae1b/32.png) [@tao](https://forum.mapillary.com/u/tao)\
**Post date:** [April 30, 2018, 4:01pm UTC](https://forum.mapillary.com/t/how-does-lookat-api-function-actually-work/1645/2 "2018-04-30T16:01:42Z")

</div>

Hi Momo, the parameter you need is `lookat=lng,lat`. See [https://a.mapillary.com/#search-images](https://a.mapillary.com/#search-images)

However as mentioned in the docs, it’s usually not enough to just have a `lookat` in the URL, which will pull images all over the world that looks at the point. Instead, `lookat` is usually used together with spatial filters like `bbox` or `closeto` to filter images that look at the point in an area of interest.

Examples:

search for images that are looking at location `12,50` within 100 meters around the location `12,50`

```auto
/v3/images?lookat=12,50&closeto=12,50&radius=100

```

search for images that are looking at location `12,50`, in the bounding box `0,0,20,20` (between left-bottom `0,0` and right-top `20,20`):

```auto
/v3/images?lookat=12,50&bbox=0,0,20,20

```

Regards,  
Tao Peng

---

<div class="post-metadata">

**Author:** ![momut1](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.mapillary.com/momut1/32/1094_2.png) [@momut1](https://forum.mapillary.com/u/momut1)\
**Post date:** [May 2, 2018, 7:58am UTC](https://forum.mapillary.com/t/how-does-lookat-api-function-actually-work/1645/3 "2018-05-02T07:58:50Z")

</div>

Hello Tao,

Thanks for the reply, but this “use” part of the function documentation is quite clear to me. I successfully use it to query and harvest images via the API. My question relates to the geometry/trigonometry that sits behind the `&lookat=` call. For reference I provide a sample cURL request as a code block in my R script:

```
 res <-GET(paste0( "https://a.mapillary.com/v3/images/?",
                      "closeto=",lon,",",lat,
                      "&radius=",200,
                      "&start_time=",start_season,
                      "&end_time=",end_season,
                      "&lookat=",lon,",",lat,
                      "&client_id=",clientID))

```

My question is thus related not to the “how to use”, but rater to “how does it work” semantics. The example snippet I was expecting would be something including SIN/COSINE trigonometric functions to estimate angle between the image and the point being looked at and then comparing this for each image to some threshold angle range, after/before which the point would be deemed “invisible” from the location of the image.

Do you have an answer for this question?

Regards,

M

---

<div class="post-metadata">

**Author:** ![tao](https://avatars.discourse-cdn.com/v4/letter/t/f9ae1b/32.png) [@tao](https://forum.mapillary.com/u/tao)\
**Post date:** [May 3, 2018, 9:15am UTC](https://forum.mapillary.com/t/how-does-lookat-api-function-actually-work/1645/4 "2018-05-03T09:15:57Z")

</div>

Assume your query is `/v3/images?lookat=12,50&bbox=0,0,20,20`, it works as follows:

1. fetch images in the bounding box
2. for each image in the bounding box  
a. calculate the bearing from the image and the `lookat` location  
b. check if the bearing falls in the range between `ca - 50º` and `ca + 50º`, where `ca` means the image’s camera angle.  
c. if yes, add this image to the response
3. return images in the response

---

<div class="post-metadata">

**Author:** ![momut1](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.mapillary.com/momut1/32/1094_2.png) [@momut1](https://forum.mapillary.com/u/momut1)\
**Post date:** [May 3, 2018, 11:49am UTC](https://forum.mapillary.com/t/how-does-lookat-api-function-actually-work/1645/5 "2018-05-03T11:49:07Z")

</div>

Yes! Thank you, this is what I was looking for.

Just one thing: when you say “bearing from the image and the `lookat` location”, do you mean an azimuth angle between the position where the image was taken and the `lookat` position? If so - what are the units of these angles. I am asking because currently I am trying to work with an azimuth angle held in degrees, where 0 is North, 180 is South, etc. I am questioning whether this measurement scale is applicable to your `lookat` functionality, or whether you calculate your “bearing” in a local angle?

EDIT:  
One more thing though: what is the reasoning behind using the -/+ **50** (exactly) degrees from the car ca? Is it a threshold you empirically arrived at?

Regards,  
M
