I am doing React application for getting me closest gas station, application should be able to show on map where is closest gas station depending on location, I got to a part where I can get latitude and longitude of someone but have no idea how to continue, Would love it if someone is able to help, Here is my code for getting latitude and longitude
import React from 'react';
import './App.css';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
latitude: null,
longitude: null,
};
this.getLocation = this.getLocation.bind(this);
this.getCoordinates=this.getCoordinates.bind(this)
}
getLocation(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(this.getCoordinates);
} else {
alert("Geolocation is not supported by this browser.");
}
}
getCoordinates(position){
this.setState({
latitude: position.coords.latitude,
longitude: position.coords.longitude
})
}
render() {
return (
<div classname="App">
<h2>
Location</h2>
<button onClick={this.getLocation}>Show coordinates</button>
<h4>Coordinates</h4>
<p>Latitude:{this.state.latitude}</p>
<p>longitude:{this.state.longitude}</p>
</div>
)
}
}
export default App; `