小编Ame*_*she的帖子

Mapbox GL 地图不以初始位置为中心

我在 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,即芝加哥(根据我的控制台日志,我可以验证初始化地图时坐标是否存在)。我从谷歌地方获取这些坐标。当我运行地图时,由于某种原因它以南极洲为中心:

在此输入图像描述

我为此使用默认样式和图块集。我应该怎么办?

google-maps mapbox mapbox-gl mapbox-gl-js angular

1
推荐指数
1
解决办法
4382
查看次数

标签 统计

angular ×1

google-maps ×1

mapbox ×1

mapbox-gl ×1

mapbox-gl-js ×1