Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 230523

How can I have two markers on native google maps and show route?

$
0
0

Hello guys,

How can I get two markers on native google maps?
In my project, I need one dynamic marker and one fixed marker.

This is how I’m adding my first marker which is getting its latitude and longitude from a data provider sending the numbers in “place” data object.

        addMarker() {
          this.map.addMarker({
            title: 'My Marker',
            icon: 'blue',
            animation: 'DROP',
            position: {
              lat: this.place.lat,
              lng: this.place.lng
            }
          })
          .then(marker => {
            marker.on(GoogleMapsEvent.MARKER_CLICK).subscribe(() => {
              alert('Marker Clicked');
            });
          });
        }

I tried to add another marker with fixed longitude and latitude but it doesn’t really work. Google maps shows only one marker added later.

addMarker2() {
          this.map.addMarker({
            title: 'My Marker',
            icon: 'blue',
            animation: 'DROP',
            position: {
              lat: -33,
              lng: 773231
            }
          })
          .then(marker => {
            marker.on(GoogleMapsEvent.MARKER_CLICK).subscribe(() => {
              alert('Marker Clicked');
            });
          });
        }

and how can I show route between the two markers?

Thanks in advance,


Viewing all articles
Browse latest Browse all 230523