cordova-plugin-googlemaps
cordova-plugin-googlemaps copied to clipboard
marker does not change position
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');
});
});
});
})
}
this.markers[indice] = this.map.addMarker(markerOptions);
This is incorrect.
How to make several markers? and you can move only one at a time, the addMarkers did not work.
this.map.addMarker(markerOptions).then((marker) => {
this.markers[indice] = marker;
});
Good, setPosition worked thank you, one last question to animate the marker linearly which function is used?
https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.0.0/class/utilities/geometry/spherical/interpolate/README.md