我想知道我可以使用Ionic的传单实时跟踪我的位置,我能够获得我当前的位置,但我也想在移动时跟踪它
this.map.locate({
setView: true,
maxZoom: 16
}).on('locationfound', (e) => {
let markerGroup = leaflet.featureGroup();
this.marker = leaflet.marker([e.latitude, e.longitude], { icon: carIcon }).addTo(this.map);
locate
接受一个watch
选项,该选项可让您不断更新标记位置:
监视类型:布尔值 默认值:false
如果为 true,则使用 W3CwatchPosition
方法开始连续监视位置更改(而不是检测一次(。您可以稍后使用map.stopLocate()
方法停止观看。
例如:
this.map.locate({
watch: true,
setView: true,
maxZoom: 16
}).on('locationfound', (e) => {
if (!this.marker) {
this.marker = leaflet.marker([e.latitude, e.longitude], { icon: carIcon }).addTo(this.map);
} else {
this.marker.setLatLng([e.latitude, e.longitude]);
}
}