我在 Angular 2 中使用 mapbox gl 来根据用户当前位置绘制地图。我的代码如下:
executemap() {
console.log(this.locationService.currentLat, this.locationService.currentLng);
this.map = new mapbox.Map({
style: 'mapbox://styles/mapbox/streets-v10',
center: [this.locationService.currentLat, this.locationService.currentLng],
zoom: 9,
container: 'map'
});
console.log('map loaded');
console.log(this.map);
console.log(this.map.getCenter().toString());
var latLng = new mapbox.LngLat(this.locationService.currentLat,this.locationService.currentLng);
this.map.resize();
this.map.setZoom(2);
Run Code Online (Sandbox Code Playgroud)
}
在此示例中,我使用坐标 41.8692324 -87.6630301,即芝加哥(根据我的控制台日志,我可以验证初始化地图时坐标是否存在)。我从谷歌地方获取这些坐标。当我运行地图时,由于某种原因它以南极洲为中心:
我为此使用默认样式和图块集。我应该怎么办?