Last active
September 29, 2020 15:13
-
-
Save phpsmarter/8ac6d226ab64eab2ffc2e40ff28b353c to your computer and use it in GitHub Desktop.
expo Map method
This file contains 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 { Platform} from 'react-native'; | |
import { MapView,Location, Permissions,Constants } from 'expo'; | |
export default class App extends React.Component { | |
state = { | |
location: null, | |
errorMessage: null, | |
}; | |
componentWillMount() { | |
if (Platform.OS === 'android' && !Constants.isDevice) { | |
this.setState({ | |
errorMessage: 'Oops, this will not work on Sketch in an Android emulator. Try it on your device!', | |
}); | |
} else { | |
this._getLocationAsync(); | |
} | |
} | |
_getLocationAsync = async () => { | |
let { status } = await Permissions.askAsync(Permissions.LOCATION); | |
if (status !== 'granted') { | |
this.setState({ | |
errorMessage: 'Permission to access location was denied', | |
}); | |
} | |
let location = await Location.getCurrentPositionAsync({}); | |
this.setState({ location }); | |
console.log(this.state.location) | |
}; | |
render() { | |
return ( | |
<MapView | |
style={{ flex: 1 }} | |
initialRegion={{ | |
latitude:110.4323532 , | |
longitude:21.2353182, | |
latitudeDelta: 0.0922, | |
longitudeDelta: 0.0421, | |
}} | |
/> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment