How to show all markers?

Asked

Viewed 146 times

0

I am developing an Ionic app where I need to show several points on the Google Maps map, I add all points as markers on the map and place the camera position to the center of the points.

pontos = [[23,13], [11, 45], ..., [22, 21]];

for (let p of pontos) {
    this.map.addMarkerSync({
        position: {
            lat: p[0],
            lng: p[1]
        }
    });
}

The problem is that the zoom does not allow all points to be viewed. My question is: how do I calculate the zoom so that all the added points appear?

  • Have you ever tried to calculate in any way? It would be good to put your code so that we have a sense of how to help?

2 answers

0

Create a Latlngbounds that includes all points.

Use CameraUpdateFactory.newLatLngBounds(LatLngBounds bounds, int padding) to obtain a Cameraupdate that will cause the camera to display the screen-centered Latlngbounds by zooming in as much as possible.

Use this Cameraupdate in the method animateCamera() map.

The terminology used is for Android Java. I suppose there is the equivalent in Ionic/javascript.

-1

var myLatLng = {lat: -23.584460, lng: -46.718901};
          this.map = new window.google.maps.Map(document.getElementById('map'), {
          center: myLatLng,
          zoom: 9,
          icon: this.image
        });
}

I used that zoom and I could see everything, zoom in and back

  • That zoom is too big. These points can be each in a different city, or each in a different state, or all within the same neighborhood. I can’t predict, so a fixed zoom value doesn’t work.

  • I don’t understand, in order to visualize all, it will need a large zoom and when you find what you’re looking for, you should zoom in on it, right? sorry I can’t help

  • I want to visualize them all, not focus on one. Only when the dots are in multiple states I need a small zoom, when the dots are in the same city I need a large zoom.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.