Created
December 3, 2015 13:37
-
-
Save MicheleBertoli/c118522aa3f5a0c1e988 to your computer and use it in GitHub Desktop.
Geolocation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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