<html>
<head>
<meta charset='utf-8' />
<title>Locate the user</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v1.2.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v1.2.1/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoicnRrbWFwIiwiYSI6ImNqejJvbjloczA0dGczZG1uamRxNHNrM24ifQ.oJBnsuU9ILbPW7Ehz2cyPA';
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'https://maputnik.github.io/osm-liberty/style.json',
center: [-96, 37.8], // starting position
zoom: 3 // starting zoom
});
// Add geolocate control to the map.
map.addControl(new mapboxgl.GeolocateControl({
positionOptions: {
enableHighAccuracy: true
},
trackUserLocation: true
}));
</script>
</body>
</html>
var map = new mapboxgl.Map({
container: 'map', // container id
style: {
"version": 8,
"sources": {
"raster-tiles": {
"type": "raster",
"tiles": ["https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"],
"tileSize": 256,
"attribution": 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'
}
},
"layers": [{
"id": "simple-tiles",
"type": "raster",
"source": "raster-tiles",
"minzoom": 0,
"maxzoom": 22
}]
},
center: [-74.50, 40], // starting position
zoom: 2 // starting zoom
});
{s}
в адресе на сработает, надо экспериментировать, но как-то так. function dadata($url, $data) {
$options = [
'http' => [
'method' => 'POST',
'header' => [
'Content-type: application/json',
'Authorization: Token ' . DADATA_TOKEN,
'X-Secret: ' . DADATA_SECRET,
],
'content' => json_encode($data),
],
];
$context = stream_context_create($options);
$contents = file_get_contents($url, false, $context);
return json_decode($contents)[0];
}
public function ApiPos($fields)
{
$ch = curl_init($serverUrl. '?' .http_build_query($fields));
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json',
"Authorization: Bearer {$token}"
);
$result = curl_exec($ch);
$result = json_decode($result, true);
curl_close($ch);
return $result;
}