location.js 687 Bytes
import React, { Component } from "react";
import axios from 'axios';

class App extends Component {
 constructor(props) {
    super(props);
    this.state = {
    };
  }

  render() {
    let data = {
      lat : null,
      lag : null
    };
    navigator.geolocation.getCurrentPosition(function(position) {
      data = {
        lat : position.coords.latitude,
        lag : position.coords.longitude
      };
      axios.post('/locate',  JSON.stringify(data), {
        headers: {
          "Content-Type": `application/json`,
        },
      }).then((res) => {
        console.log("complete");
      });
    });
    return (
     <div>
      </div>
    );
  }
}
export default App;