import React, { Component } from "react";
        
      class Location extends Component {
        
        constructor(props) {
          super(props);
          this.state = {};
        }
        
        componentDidMount() {
          if (navigator.geolocation) {
            navigator.geolocation.watchPosition(function(position) {
              console.log("Latitude is :", position.coords.latitude);
              console.log("Longitude is :", position.coords.longitude);
              const l1 = position.coords.latitude;
              const l2 = position.coords.longitude;
              console.log("L1 is :", l1);
              console.log("L2 is :", l2);
              localStorage.setItem('latitude', l1)
              localStorage.setItem('longitude', l2)
            });
          }
        }
        
        render() {
          return (
            <div>
            </div>
          );
        }
      }
        
      export default Location;

      Javascript language logoReact Location Components

      Location
      Basic Fundraising Website

      This code creates a Location component which will allow the user to input their latitude and longitude. The component will render a simple div with the user's latitude and longitude displayed inside it.

      Shortcut: react.fr.location

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.