Show searches of API Request when zooming

Hi! I have an api that returns differents locations according to my geolocation, but paginated. Since we can’t show paginated results in a map, the idea is when the user starts to zoom, calculating on the distance, with this formula: distance = Math.round(this.getMeterPerPixel(zoom) * width), where this.getMeterPerPixel returns from a hash the number of meters per pixel according to the zoom level, where zoom is the zoom level and width is the clientwidth of the container map, it returns you less results which we avoid the issue with the pagination. But I notice that the map, if I get back 30 results, only shows 3 markers, (for example). In other words, in a certain radius when doing zoom I want to visualize the 30 results.

I don’t know if I explained myself clear.

But see the screen shot:

I would really appreciate it if someone had to do something like this, and give me a solution.

Thanks!

Does this API allows to search within a defined bounding box?

“if I get back 30 results, only shows 3 markers” - we don’t have enough details to help here.
Does it means that other results are outside of what user can see on the map?

1 Like

Does this API allows to search within a defined bounding box? Wha do you mean? What do I need for the api to allow that search?
Exactly, like you said.

1 Like

Given a certain distance, lat and long. It returns this.
“geolocation”: {
“postal_code”: “90079”,
“city_locality”: “Los Angeles”,
“state_region”: “CA”,
“latitude”: 34.0522,
“longitude”: -118.2427,
“county”: “Los Angeles”,
“friendly_name”: “Los Angeles, CA”
}

As info in general. And then it has an array of locations with similar object as above. I can’t send more info.

1 Like

With SDK for Web you can use getBounds() to retrieve southwest and northeast corners of what user can see on a map.
Then if a service allows to search within defined bounds/bounding box then you can use the values from getBounds(). That should simplify your code.

When it comes to the results - you are getting 30 results, but only 3 are shown on a map. Can you tell something more that could help to determine why they are not shown?

1 Like

Thats what I don’t know why. Like I sent on the screenshot, maybe its the width of the map or I don’t know. I’m not an expert, that why I’m asking here in the forum. :disappointed: :woman_shrugging:

Without the code it is just guessing.
Can you do some debugging and check if these results fit within bounds of the map?

1 Like