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.
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 …
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.