ossy
ossy

Reputation: 1

Leaflet L.control.locate()

I'm trying to create a small webpage with an Openstreetmap and a icon to get my current position.

Heree is my code, but it's not working and I don't know why (small noob)

Thansk in adavnce for your help.

Best regards Ossy

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
   integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
   crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
   integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
   crossorigin=""></script>   
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet.locatecontrol/dist/L.Control.Locate.min.css"
<script src="https://cdn.jsdelivr.net/npm/leaflet.locatecontrol/dist/L.Control.Locate.min.js" charset="utf-8"></script>

<title>My Openstreetmap Test</title>
</head>   

<body>
 <style>#mymapid{height:700px;}</style>
 <div id="mymapid"></div>

<script>
var mylat = 46.9;
var mylon = 4.6833;
var myzoom = 16;
var mymapid = null;

function initMap() {
    var mymap = L.map('mymapid').setView([mylat,mylon], myzoom);

    L.tileLayer('https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', {
        attribution: 'données à <a href="//osm.org/copyright">OpenStreetMap</a>/ODbL - rendu <a href="//openstreetmap.fr">OSM France</a>',
        minZoom: 1,
        maxZoom: 20
    }).addTo(mymap);


    var mk = L.marker([mylat,mylon]).addTo(mymap);

    var lc = L.control.locate().addTo(mymap);   
};

window.onload = function(){
    initMap(); 
};
</script>
</body>
</head>

Upvotes: 0

Views: 4288

Answers (1)

IanC
IanC

Reputation: 883

You have some typos in your html, otherwise this works fine. The last two <link tags are not terminated with /> as they should be and your final tag should be </html> and not </head>

I ran this on Glitch and it worked ok with the typos fixed:

https://glitch.com/~ianc-leaflet2

Upvotes: 1

Related Questions