Skip to content
Snippets Groups Projects
Commit 31817ed3 authored by Joni Laukka's avatar Joni Laukka
Browse files

Geolocation options added to get more accurate location

parent 1807a6ba
No related branches found
No related tags found
1 merge request!3Get own location
...@@ -12,27 +12,33 @@ class UserMap extends Component { ...@@ -12,27 +12,33 @@ class UserMap extends Component {
componentDidMount(){ componentDidMount(){
this.getCurrentPosition((position) => { this.getCurrentPosition((position) => {
if(position != null){ this.setState({
this.setState({ ownLat: position.coords.latitude,
ownLat: position.lat, ownLng: position.coords.longitude,
ownLng: position.lng, });
});
}
}); });
} }
getCurrentPosition(callback){ getCurrentPosition(callback){
if(!navigator.geolocation){ if(!navigator.geolocation){
console.log("Can't get geolocation :/"); console.log("Can't get geolocation :/");
callback(null);
} }
else{ else{
navigator.geolocation.getCurrentPosition((position)=> { // Position tracking options
callback({ const options = {
lat: position.coords.latitude, enableHighAccuracy: true,
lng: position.coords.longitude timeout: 30000,
}); maximumAge: 0
}); }
navigator.geolocation.getCurrentPosition((position) =>{
//success
if(position != null){
callback(position);
}
}, (error) =>{
console.log(error);
}, options);
} }
} }
...@@ -48,10 +54,14 @@ class UserMap extends Component { ...@@ -48,10 +54,14 @@ class UserMap extends Component {
Se on perjantai, my dudes <br /> Se on perjantai, my dudes <br />
</Popup> </Popup>
</Marker> </Marker>
{this.state.ownLat !== null && <Marker position={[this.state.ownLat, this.state.ownLng]}></Marker>} {this.state.ownLat !== null && <Marker position={[this.state.ownLat, this.state.ownLng]}>
<Popup>
User's real position.<br />
</Popup>
</Marker>}
</Map> </Map>
); );
} }
} }
export default UserMap; export default UserMap;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment