我是 iOS 开发和 Mapbox 的新手,如果问题听起来很愚蠢,我很抱歉,但我在任何地方都找不到答案。\n我有一张地图和上面的注释。我想在用户触摸并按住注释(长按手势)时显示一些其他信息。我有长按手势来工作,但找到了找到被触摸的注释的方法,或者至少是它的索引。到目前为止我是这样的:
\n\nclass eventsMapController: UIViewController, MGLMapViewDelegate {\noverride func viewDidLoad() {\n super.viewDidLoad()\n mapView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]\n\n // Set the map\'s bounds to Oslo 59.920269,10.71167\n //let bounds = MGLCoordinateBounds(sw: CLLocationCoordinate2D(latitude: 59.925861, longitude: 10.712185),\n // ne: CLLocationCoordinate2D(latitude: 59.889798, longitude: 10.794754)) \n view.addSubview(mapView)\n\n // Set the map view\xe2\x80\x98s delegate property\n mapView.delegate = self\n\n let myGesture = UILongPressGestureRecognizer(target: self, action: #selector(eventsMapController.testLongGesture))\n myGesture.minimumPressDuration = 0.8\n mapView.addGestureRecognizer(myGesture) \n}\nfunc testLongGesture(long: UILongPressGestureRecognizer){\n if long.state == .Began{ \n print("begin", long)\n }\n}\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我正在添加这样的注释
\n\nlet pointAnotation …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用MapBox 服务通过 GeoCoding 和 AutoComplete 建议用户附近的地点:
compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:5.0.2@aar'){
transitive=true
}
compile ('com.mapbox.mapboxsdk:mapbox-android-services:2.0.0@aar'){
transitive=true
}
Run Code Online (Sandbox Code Playgroud)
但是像 GeocoderAutoCompleteView 这样的一些类不包含在这个包中,我无法导入该类。
一切都很好,但突然我得到了这个错误。我用谷歌搜索了很多次但没有解决方案。有人可以帮我吗?

我用过的代码
import React, { Component } from 'react';
import MapboxGl from 'mapbox-gl/dist/mapbox-gl';
import '../App.css';
class MapContent extends Component {
componentDidMount() {
MapboxGl.accessToken = ACCESS_TOKEN;
var map = new MapboxGl.Map({
container: this.Mapcontainer,
style: 'mapbox://styles/mapbox/streets-v9',
center: [-74.50, 40], // starting position
zoom: 9 // starting zoom
});
var geocoder = new MapboxGeocoder({
accessToken: MapboxGl.accessToken
});
map.addControl(geocoder);
}
render() {
return (
<div className='MapContent' ref={(x) => { this.Mapcontainer = x }}>
</div>
)
}
}
export default MapContent;
Run Code Online (Sandbox Code Playgroud) 我在 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,即芝加哥(根据我的控制台日志,我可以验证初始化地图时坐标是否存在)。我从谷歌地方获取这些坐标。当我运行地图时,由于某种原因它以南极洲为中心:
我为此使用默认样式和图块集。我应该怎么办?
我mbtiles使用 Tippecanoe 生成了一个文件,仅使用-zg和--drop-densest-as-needed作为额外参数。我将文件上传到 Mapbox Studio,无论是在 Studio 中还是通过移动应用程序加载图块时,一切都运行良好。
然后我尝试使用 Go 中的一个非常基本的 HTTP 服务器来自托管这些图块。图块从 SQLite 转移到 PostgreSQL 数据库(原因是 Go + PSQL 是应用程序的现有堆栈)。
由于某种原因,这些功能会根据缩放级别而变化。在级别 1 上,本应位于美国的数据位于南极洲,在缩放级别 2 上,数据位于智利海岸附近,等等。唯一正常工作的是级别 0,因为只有一个图块。
我检查了在旧金山缩放级别 11 时 Mapbox 请求的图块:第 327 列,第 791 行。文件中不存在此行/列组合的图块,.mbtiles尽管那里有数据。
除了使用 z/x/y 在数据库中查找 mbtile 之外,还需要对它们执行其他操作吗?或者也许需要在应用程序端配置一些东西?
服务器代码:
row := db.QueryRow(`
SELECT tile_data FROM tiles
WHERE
zoom_level = $1
AND tile_column = $2
AND tile_row = $3
`,
z, x, y,
)
Run Code Online (Sandbox Code Playgroud)
在安卓上:
map.addSource(
VectorSource(
"tiles",
TileSet("2.2.0", "http://my.local.server:4000/tiles/{z}/{x}/{y}.mvt?key=2448A697EACDDC41432AAD9A1833E")
) …Run Code Online (Sandbox Code Playgroud) 我在 Mapbox 中使用数据驱动样式来自定义从 GeoJson 源获取的线条样式。除了将线变成多边形或在附近绘制第二条线之外,还有什么方法可以以某种方式绘制双线吗?
我正在遵循https://docs.mapbox.com/help/tutorials/android-navigation-sdk/上的 MabBox 教程来制作一个使用其基本元素的简单导航片段。
我已经知道 MapBox 需要在膨胀视图之前实例化,因为我之前在另一个片段上进行过测试,以测试该片段是 TabLayout 组件的一部分,但是,在这个组件中,只有一个 Activity 加载我所在的片段使用 SDK,在这种情况下,它会抛出与我之前修复的相同的错误,因为我将其放在膨胀布局之后。
出现的错误是这样的:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.parkingclientapplication, PID: 14257
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.parkingclientapplication/com.example.parkingclientapplication.activities.MapDirectionActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class com.mapbox.mapboxsdk.maps.MapView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class …Run Code Online (Sandbox Code Playgroud) 我通过添加链接到它们的源和图层来初始化 Mapbox 地图。
mapbox.addSource(MY_SOURCE, {
'type': 'geojson',
'data': {
'type': 'FeatureCollection',
'features': [],
},
});
mapbox.addLayer({
'id': MY_LAYER,
'type': 'circle',
'source': MY_SOURCE,
'paint': {
'circle-radius': 6,
'circle-color': '#d31467',
},
});
Run Code Online (Sandbox Code Playgroud)
我的目标是 - 我希望一次完成这些定义 - 如果我需要更新源代码,我只需:
mapbox.getSource(MY_SOURCE).setData(geojson);
Run Code Online (Sandbox Code Playgroud)
有时我需要清除所有多边形、所有点、所有东西。我怎样才能做到这一点而不丢失所有这些定义?我只能看到.removeSource, .removeLayer- 这告诉我实际上需要重新创建这些定义。
有没有一种破坏性较小的方法呢?
我想更改 mapboxGl 上的鼠标单击功能。我需要在地图上实现右键平移,但没有相关文档。因此,我尝试禁用右键单击地图旋转并启用平移,但没有任何效果,它只是禁用了旋转,但未触发平移。
我想知道是否有一种方法可以以编程方式启动和停止拖动/平移,我知道您可以启用它,但我需要实际开始平移。
想让它变得干净简单,我想你可以在鼠标移动上添加侦听器,然后更改地图边界,但它看起来不太好。有没有更简单的方法来启动dragPan?
我正在尝试禁用地图的所有移动,除了旋转和缩放到设定点之外。但在触摸设备上,我仍然可以用两根手指将“相机”从设定点移动,它在非触摸设备上工作得很好。
这是我目前所拥有的,但并不能完全工作,我仍然可以用触摸设备上的两根手指移动相机中心点。我正在使用带有离子/角度的打字稿。
this.map = new mapboxgl.Map({
container: 'game_map',
style: 'mapbox://styles/mapbox/light-v10',
center: [coords],
zoom: 20,
touchZoomRotate: {around: 'center'},
scrollZoom: {around: 'center'},
pitch: 60,
bearing: -60,
antialias: true,
attributionControl: false,
maxZoom: 22,
minZoom: 17
});
Run Code Online (Sandbox Code Playgroud) mapbox ×10
mapbox-gl-js ×6
android ×2
javascript ×2
mapbox-gl ×2
angular ×1
annotations ×1
google-maps ×1
ios ×1
kotlin ×1
mbtiles ×1
reactjs ×1
swift ×1
tippecanoe ×1
typescript ×1