Skip to content

Instantly share code, notes, and snippets.

@MicheleBertoli
Created December 3, 2015 13:37
Show Gist options
  • Save MicheleBertoli/c118522aa3f5a0c1e988 to your computer and use it in GitHub Desktop.
Save MicheleBertoli/c118522aa3f5a0c1e988 to your computer and use it in GitHub Desktop.
Geolocation
import React from 'react';
import ReactDOM from 'react-dom';
import {Gmaps} from 'react-gmaps';
const App = React.createClass({
onMapCreated(map) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
map.setCenter({
lat: position.coords.latitude,
lng: position.coords.longitude
});
});
}
},
render() {
return (
<Gmaps
width={'400px'}
height={'300px'}
lat={0}
lng={0}
zoom={12}
onMapCreated={this.onMapCreated}/>
);
}
});
ReactDOM.render(<App />, document.getElementById('gmaps'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment