title: leafletjs get coordinates from onLocationFound function
body: <p>I am working with leafletjs API.</p>
  
  <p>I do not have experience with JS and I couldn't find any answer here.</p>
  
  <p>I am trying to combine using geolocation service with leaflet routing service.</p>
  
  <p>My goal is to get </p>
  
  <blockquote>
    <p>latlng</p>
  </blockquote>
  
  <p>value from </p>
  
  <blockquote>
    <p>onLocationFound</p>
  </blockquote>
  
  <p>function and passed that </p>
  
  <p>information to first </p>
  
  <blockquote>
    <p>waypoint</p>
  </blockquote>
  
  <p>in routing service.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//INITIALIZE MAP...
  var map = L.map('map');
  
  L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
   attribution: '&amp;copy; &lt;a href="https://osm.org/copyright"&gt;OpenStreetMap&lt;/a&gt; contributors'
  }).addTo(map);
  // LOCATION SERVICE 
  map.locate({setView: true, maxZoom: 16});
  function onLocationFound(e) {
      var radius = e.accuracy / 2;
       L.marker(e.latlng).addTo(map)
  
  
  }
   
  
  map.on('locationfound', onLocationFound);
  
  function onLocationError(e) {
      alert(e.message);
  }
  
  map.on('locationerror', onLocationError);
  //End of Location service, 
  //GET LATLNG PARAMETERS AFTER CLICK IN CONSOLE
  map.on('click', function(e)  
    {
  
    tempLatitude = e.latlng.lat;
  
    tempLongitude = e.latlng.lng;
    console.log(tempLongitude);
  console.log(tempLatitude);
  });
  
  
  // ROUTING SERVICE
  var control = L.Routing.control(L.extend(window.lrmConfig, {
  
  
    waypoints: [
   L.latLng(57.74, 11.94),
    L.latLng(57.6792, 11.949)
   ],
   geocoder: L.Control.Geocoder.nominatim(),
   routeWhileDragging: true,
   reverseWaypoints: true,
   showAlternatives: true,
   altLineOptions: {
    styles: [
     {color: 'black', opacity: 0.15, weight: 9},
     {color: 'white', opacity: 0.8, weight: 6},
     {color: 'blue', opacity: 0.5, weight: 2}
    ]
   }
  })).addTo(map);
  
  
  
  
  
  L.Routing.errorControl(control).addTo(map);</code></pre>
  </div>
  </div>
  </p>
  
  <p>.</p>