Automatic map scaling

Friends, I have another question: how to implement automatic scaling of Google maps?

Situation: There is the current location of the user, which we show on the map. After that, we create two or three labels at some distance from the user. The task: to automatically mass scale the map so that it would show both the user’s location and all the placemarks on the map.

Now I easily display the user’s current location on the map (thanks to the creators of Thunkable), and all the necessary labels - but if the label goes beyond the visible field of the map - until the user zooms out on his own - the label is not visible.

How can this be done?

1 Like

Use the zoom level
image to change the view.

1 Like

This option, yes, I know - but it is not very good, because if the labels are far from each other, I may not guess with the scaling and make it too large or too small … :frowning:

1 Like

Hey @lavrynenko :wave:

I think there’s 4 questions to answer here

  1. How far apart are my two furthest POI

  2. How do figure ^^^^ this out?

  3. How many km wide is the map at each zoom level

  4. Based on the above, what zoom level would encompass all my POi

If you can answer these, you can achieve this “auto scaling” behavior.

2 Likes

By the way, this is a very interesting option! Thanks! I will conduct experiments :slight_smile:

The MAP object in Google has a method called fitbounds() which can be used a JavaScript code to first add all markers in a list (LatLngBond) and then call fitbounds() passing this list as the parameters. This will autozoom the map to fit all markers.

This can be done in a Web Viewer.

Interestingly, the fitbounds() method allows passing only two coordinates which are the two furthest point, the documentation names them as NE and SW to display the complete markers without having to add all of them to the list.

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