Html 如何在角应用程序中在单张开放街道地图中放置当前位置

Html 如何在角应用程序中在单张开放街道地图中放置当前位置,html,angular,typescript,leaflet,angular8,Html,Angular,Typescript,Leaflet,Angular8,我有一个角度的应用程序,我已经放置了使用传单打开街道地图地图。我需要放置该地图的当前纬度和经度。(必须根据位置进行更改)。 我的问题是如何使用传单地图放置地图的当前坐标。 我的component.ts代码是 .component.ts var map = L.map('map').setView([13.0827, 80.2707], 3); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attri

我有一个角度的应用程序,我已经放置了使用传单打开街道地图地图。我需要放置该地图的当前纬度和经度。(必须根据位置进行更改)。 我的问题是如何使用传单地图放置地图的当前坐标。

我的component.ts代码是

.component.ts

 var  map = L.map('map').setView([13.0827, 80.2707], 3);

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
 attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'

    
} ).addTo(map);

var-map=L.map('map').setView([13.0827,80.2707],3);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'{
归属:“©贡献者”
})。地址(地图);

您可以使用导航器获取当前位置坐标

ngOnInit(){
   if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(this.setGeoLocation.bind(this));
   }
}

setGeoLocation(position: { coords: { latitude: any; longitude: any } }) {
   const {
      coords: { latitude, longitude },
   } = position;

   const  map = L.map('map').setView([latitude, longitude], 3);

   L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>contributors'
    } ).addTo(map);
}
ngOnInit(){
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(this.setGeoLocation.bind(this));
}
}
setGeoLocation(位置:{coords:{纬度:任意;经度:任意}){
常数{
坐标:{纬度,经度},
}=位置;
const map=L.map('map').setView([纬度,经度],3);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'{
归属:“©贡献者”
})。地址(地图);
}
当应用程序加载setGeoLocation函数并初始触发并更新传单地图时,在App.component.ts中标记此点

希望这能奏效