title: How to store Geolocation coordinates in mongoDB database using below code?
body: <p>i. e. Geolocation get stored after user clicks the button. I didn't understand how to send this coordinates to the post route. Please help me out.</p>
  
  
  
  <pre><code>&lt;p&gt;Click the button to get your coordinates.&lt;/p&gt;
  
  &lt;button onclick=&quot;getLocation()&quot;&gt;Try It&lt;/button&gt;
  
  &lt;p id=&quot;demo&quot;&gt;&lt;/p&gt;
  
  &lt;script&gt;
      var x = document.getElementById(&quot;demo&quot;);
  
      function getLocation() {
          if (navigator.geolocation) {
              navigator.geolocation.getCurrentPosition(showPosition);
          } else {
              x.innerHTML = &quot;Geolocation is not supported by this browser.&quot;;
          }
      }
  
      function showPosition(position) {
          x.innerHTML = &quot;Latitude: &quot; + position.coords.latitude +
              &quot;&lt;br&gt;Longitude: &quot; + position.coords.longitude;
      }
  &lt;/script&gt;
  </code></pre>