Newer
Older
instance / js / iti.js
@Nakagawa.K Nakagawa.K on 8 May 2024 1 KB 追加

          var map = L.map('map').setView([38.914544,139.836720], 14);
      L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
      }).addTo(map);
          //現在地が取得できた場合の処理

    //現在地が取得できなかった場合の処理
    function gpsError(e) {
        alert("現在地を取得できませんでした。" + e.message);
    }
    //現在地の取得
    map.locate({setView: true, maxZoom: 13, timeout: 20000});
    //成功した場合
    map.on('locationfound', gpsSuccess);
    //失敗した場合          var map = L.map('map').setView([38.914544,139.836720], 14);
      L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
      }).addTo(map);
          //現在地が取得できた場合の処理
    function gpsSuccess(e) {
        L.marker(e.latlng).addTo(map).bindPopup("現在地").openPopup();
    }
    //現在地が取得できなかった場合の処理
    function gpsError(e) {
        alert("現在地を取得できませんでした。" + e.message);
    }
    //現在地の取得
    map.locate({setView: true, maxZoom: 13, timeout: 20000});
    //成功した場合
    map.on('locationfound', gpsSuccess);
    //失敗した場合
    map.on('locationerror', gpsError);