cordova-plugin-googlemaps icon indicating copy to clipboard operation
cordova-plugin-googlemaps copied to clipboard

marker does not change position

Open manuvalentim opened this issue 9 years ago • 5 comments

I'm trying to change the position of the marker, but I can not. I need the marker to change position according to latitude and longitude.


import {
  GoogleMaps,
  GoogleMap,
  GoogleMapsEvent,
  GoogleMapOptions,
  CameraPosition,
  MarkerOptions,
  Marker, LatLng
} from '@ionic-native/google-maps';

ioReceiveLocation() {
    this.socket.on('ioReceiveLocation', (data) => {
      console.log(data);
      if (this.devices.indexOf(data.uuid) === -1) {
        this.devices.push(data.uuid);
        const indice = this.devices.indexOf(data.uuid);
        this.createMarker(data.location, indice);
      } else {
        const indice = this.devices.indexOf(data.uuid);
        this.setPositionAnimate(data.location, indice);
      }
    });
  }


  createMarker(location, indice) {
    let latlng = new LatLng(location.coords.latitude, location.coords.longitude);
    let markerOptions = {
      title: 'Ionic',
      icon: 'red',
      animation: 'BOUNCE',
      position: latlng
    };
    this.markers[indice] = this.map.addMarker(markerOptions);
  }

  setPositionAnimate(location, indice) {
    let latlng = new LatLng(location.coords.latitude, location.coords.longitude);
    this.speed = location.coords.speed * 3.6;
    this.markers[indice].setPosition(latlng);
  }


  //Fim das funcoes socket

  //Carrega o maps
  loadMap() {
    this.geolocation.getCurrentPosition().then((resp) => {
      this.mapElement = document.getElementById('map');
      let mapOptions: GoogleMapOptions = {
        camera: {
          target: {
            lat: resp.coords.latitude,
            lng: resp.coords.longitude
          },
          zoom: 18,
          tilt: 30
        }
      };
      this.map = this.googleMaps.create(this.mapElement, mapOptions);

      // Wait the MAP_READY before using any methods.
      this.map.one(GoogleMapsEvent.MAP_READY)
        .then(() => {
          console.log('Map is ready!');

          // Now you can use all methods safely.
          this.map.addMarker({
            title: 'Ionic',
            icon: 'blue',
            animation: 'BOUNCE',
            position: {
              lat: resp.coords.latitude,
              lng: resp.coords.longitude
            }
          })
            .then(marker => {
              marker.on(GoogleMapsEvent.MARKER_CLICK)
                .subscribe(() => {
                  alert('clicked');
                });
            });

        });
    })
  }

manuvalentim avatar Oct 30 '17 19:10 manuvalentim

this.markers[indice] = this.map.addMarker(markerOptions);

This is incorrect.

wf9a5m75 avatar Oct 30 '17 19:10 wf9a5m75

How to make several markers? and you can move only one at a time, the addMarkers did not work.

manuvalentim avatar Oct 30 '17 19:10 manuvalentim

this.map.addMarker(markerOptions).then((marker) => {
  this.markers[indice] = marker;
});

wf9a5m75 avatar Oct 30 '17 19:10 wf9a5m75

Good, setPosition worked thank you, one last question to animate the marker linearly which function is used?

manuvalentim avatar Oct 31 '17 11:10 manuvalentim

https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.0.0/class/utilities/geometry/spherical/interpolate/README.md

wf9a5m75 avatar Oct 31 '17 13:10 wf9a5m75