1

I'm new to reactjs and wanted to try the geolocation. I can already show the longitude and latitude but how can I get the address without using the Google Maps API? (To use Google Maps API, I need a billing account of which I do not have)

class Map extends Component {
  constructor(props) {
    super(props);
    this.state = {
      latitude: null,
      longitude: null,
      userAddress: null,
    };

    this.getLocation = this.getLocation.bind(this);
    this.getCoordinates = this.getCoordinates.bind(this);
    }

  getLocation() {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(
        this.getCoordinates,
        this.handleLocationErrors
      );
    } else {
      alert("Geolocation not supported ");
    }
  }

  getCoordinates(position) {
    this.setState({
      latitude: position.coords.latitude,
      longitude: position.coords.longitude,
    });
  }

  render() {
    return (
      <div>
        <Button onClick={this.getLocation}
        >
          Get Coordinates
        </Button>
        <p>Latitude: {this.state.latitude}</p>
        <p>Longtitude: {this.state.longitude}</p>
        <p>Address: {this.state.userAddress}</p>
      </div>
    );
  }
}
JS3
  • 1,623
  • 3
  • 23
  • 52
  • Not sure if it would fit your need. Read [this article](https://nordicapis.com/5-powerful-alternatives-to-google-maps-api/). Try [tomtom's Reverse Geocoding API](https://developer.tomtom.com/content/search-api-explorer#/). [2500 free transactions per day on all the APIs.](https://developer.tomtom.com/store/maps-api) – Ajeet Shah Apr 30 '21 at 09:35
  • [Open layers maps, with longitude and latitude get address](https://stackoverflow.com/q/50882125/2873538) – Ajeet Shah Apr 30 '21 at 09:47

1 Answers1

0

Most services require you to sign-up or pay. If you are only doing a few searches its free

Jon Jones
  • 1,014
  • 1
  • 9
  • 17
  • So, there's no other way? I've read about the Geocoding API where you can convert the latitudes and longitudes to human readable address, and it needs an API key and in order to have it, a billing account is needed. I just wonder if there's another way where I do not need to enter a billing account to use the API – JS3 Apr 30 '21 at 07:53
  • You used to be able to do it, but then people spammed it and they required a sign-up key. Unless you have loads of queries you will not be charged anything – Jon Jones Apr 30 '21 at 13:47