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>
);
}
}