Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Leaflet 传单api中的蓝色标记当前位置_Leaflet_Openstreetmap - Fatal编程技术网

Leaflet 传单api中的蓝色标记当前位置

Leaflet 传单api中的蓝色标记当前位置,leaflet,openstreetmap,Leaflet,Openstreetmap,您好,我使用网络地图,我需要显示当前位置,如map.google.com或openstreetmap.org或blue svg如何显示 <script> var map = L.map('map').fitWorld(); L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=token', { maxZoom: 18,

您好,我使用网络地图,我需要显示当前位置,如map.google.com或openstreetmap.org或blue svg如何显示

<script>
    var map = L.map('map').fitWorld();
    L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=token', {
        maxZoom: 18,            
        id: 'mapbox.streets'
    }).addTo(map);

    function onLocationFound(e) {
        var radius = e.accuracy / 2;

        L.marker(e.latlng).addTo(map)
            .bindPopup("you " + radius + " data").openPopup();
        map.setZoom( 18 );
        L.circle(e.latlng, radius).addTo(map);
    }

    function onLocationError(e) {
        alert(e.message);
    }

    map.on('locationfound', onLocationFound);
    map.on('locationerror', onLocationError);

    map.locate({setView: true, maxZoom: 16}); 

</script>

var map=L.map('map').fitWorld();
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=token',{
maxZoom:18,
id:“地图盒。街道”
}).addTo(地图);
函数onLocationFound(e){
var半径=e.精度/2;
L.标记(e.latlng).添加到(地图)
.bindPopup(“您”+半径+“数据”).openPopup();
map.setZoom(18);
L.圆(e.板条,半径)。添加到(地图);
}
函数onLocationError(e){
警报(e.message);
}
地图上('locationfound',onLocationFound);
map.on('locationerror',onLocationError);
locate({setView:true,maxZoom:16});

如果默认情况下看不到蓝色标记,您可以创建自己的图标:

var greenIcon = L.icon({
    iconUrl: 'leaf-green.png',
    shadowUrl: 'leaf-shadow.png',

    iconSize:     [38, 95], // size of the icon
    shadowSize:   [50, 64], // size of the shadow
    iconAnchor:   [22, 94], // point of the icon which will correspond to marker's location
    shadowAnchor: [4, 62],  // the same for the shadow
    popupAnchor:  [-3, -76] // point from which the popup should open relative to the iconAnchor
});

L.marker([51.5, -0.09], {icon: greenIcon}).addTo(map);

在当前视图中添加普通L.标记时,是否看到默认的传单标记图标?