javascript - MapBox 从设备浏览器的地理位置检索位置
问题描述
我需要显示 mapbox 地图,在设备的地理定位之后,我需要将 lat,lon 值存储在变量 js 中:
mapboxgl.accessToken='pk.xxxxxxxxxxx.xxxxxxxxxxxxx';
var coordinates = document.getElementById('coordinates');
var map = new mapboxgl.Map({
container: 'map',
center: [1.000, 1.000],
zoom: 1,
style: 'mapbox://styles/mapbox/streets-v11'
});
map.addControl(
new MapboxGeocoder({
accessToken: mapboxgl.accessToken,
mapboxgl: mapboxgl
})
);
map.addControl(new mapboxgl.NavigationControl());
map.addControl(
new mapboxgl.GeolocateControl({
positionOptions:{
enableHighAccuracy: true, timeout: 5000, maximumAge: 0
}, // I need to retrieve lat/lon from here
fitBoundsOptions: {maxZoom:20},
showUserHeading: true,
showUserLocation: true,
trackUserLocation: true
})
);
var geojson = {
type: 'FeatureCollection',
features: [{
type: 'Feature',
geometry: {
type: 'Point', coordinates: [94.00000,1.00000],},
properties: {title: 'Branch', description: 'nome'}
*}]*
};
geojson.features.forEach(function(marker) {
var marker = new mapboxgl.Marker({draggable:true})
.setLngLat(marker.geometry.coordinates)
.addTo(map);
function onDragEnd() {
var lngLat = marker.getLngLat();
document.getElementById("longitude").value = lngLat.lng;
document.getElementById("latitude").value = lngLat.lat;
document.getElementById("upbranch").submit();
}
marker.on('dragend', onDragEnd);
});
这是 MapBox 的地图代码我需要从地图地理位置检索坐标并在输入字段中使用它来存储数据库中的位置
解决方案
推荐阅读
- php - 使用codeigniter将数据形成数据库
- android - 如何使用ffmpeg在android中的视频上添加gl过渡?
- ios - CALayer 导致 ARC 内存泄漏
- c# - 使用 cmd.parameter c# 创建动态查询
- r - 使用 grid.arrange 排列多个绘图列表
- lazarus - 在命令行参数中使用带有 TProcess 的德语字符
- windows - Docker - 为什么 docker 更新主机文件?
- jenkins - 如何从 Jenkins 进行两次 SSH?
- android - Android URL意图:浏览器打开速度很慢
- python - Understanding Weights shape of an LSTM cell with 2-D input tensor