diff options
| author | Code WvS <code-wvs@quantentunnel.de> | 2015-03-08 11:54:46 +0100 |
|---|---|---|
| committer | Code WvS <code-wvs@quantentunnel.de> | 2015-03-08 11:54:46 +0100 |
| commit | e9282585122bdd21ae4a8ebe2463eb75290baebf (patch) | |
| tree | e94d9a577d0447702333f805f2ba9af594531a5f | |
| parent | 287e952592af81479a6f6e7962320891b5252ce6 (diff) | |
| download | snap-yow-e9282585122bdd21ae4a8ebe2463eb75290baebf.tar.gz snap-yow-e9282585122bdd21ae4a8ebe2463eb75290baebf.zip | |
simplify user location tracking
| -rwxr-xr-x | snap.html | 19 |
1 files changed, 7 insertions, 12 deletions
@@ -66,19 +66,14 @@ // Grabbing values via global variables from deep inside Snap! is easier // Possible drawback: Multiple worlds could conflict - function setGlobalPosition (e) { + function locationfound(e) { + if (!window.geoposition) { + // Sets the view on the first locate + map.setView(e.latlng, 18); + } window.geoposition = e.latlng; } - // Sets the view on the first locate - function firstLocate (e) { - map.stopLocate(); - map.setView(e.latlng, 18); - setGlobalPosition(e); - map.on('locationfound', setGlobalPosition); - map.locate({watch: true, enableHighAccuracy: true}); - } - window.map = map; window.layer = layer; @@ -107,8 +102,8 @@ }).addTo(map); // continuously update the local location variable - map.on('locationfound', firstLocate); - map.locate({enableHighAccuracy: true}); + map.on('locationfound', locationfound); + map.locate({watch: true, enableHighAccuracy: true}); // OSMBuildings provides fancy 3D buildings new OSMBuildings(map).load(); |
