add marker to HouseLocation
This commit is contained in:
parent
74e3960626
commit
e8e0cde796
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {StyleSheet, View} from 'react-native';
|
import {StyleSheet, View, Text} from 'react-native';
|
||||||
import MapView, {PROVIDER_GOOGLE} from 'react-native-maps'; // remove PROVIDER_GOOGLE import if not using Google Maps
|
import MapView, {PROVIDER_GOOGLE, Marker, Callout} from 'react-native-maps'; // remove PROVIDER_GOOGLE import if not using Google Maps
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
...StyleSheet.absoluteFillObject,
|
...StyleSheet.absoluteFillObject,
|
||||||
|
@ -16,18 +16,44 @@ const styles = StyleSheet.create({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const HouseLocation = () => (
|
const HouseLocation = () => {
|
||||||
|
const [marker, setMarker] = React.useState({
|
||||||
|
latitude: 37.78825,
|
||||||
|
longitude: -122.4324,
|
||||||
|
});
|
||||||
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<MapView
|
<MapView
|
||||||
provider={PROVIDER_GOOGLE} // remove if not using Google Maps
|
provider={PROVIDER_GOOGLE} // remove if not using Google Maps
|
||||||
style={styles.map}
|
style={styles.map}
|
||||||
region={{
|
initialRegion={{
|
||||||
latitude: 37.78825,
|
latitude: 37.78825,
|
||||||
longitude: -122.4324,
|
longitude: -122.4324,
|
||||||
latitudeDelta: 0.015,
|
latitudeDelta: 0.015,
|
||||||
longitudeDelta: 0.0121,
|
longitudeDelta: 0.0121,
|
||||||
|
}}>
|
||||||
|
<Marker
|
||||||
|
coordinate={marker}
|
||||||
|
draggable={true}
|
||||||
|
onDragEnd = {(e) => {
|
||||||
|
setMarker({
|
||||||
|
latitude: e.nativeEvent.coordinate.latitude,
|
||||||
|
longitude: e.nativeEvent.coordinate.longitude,
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}}
|
}}
|
||||||
/>
|
>
|
||||||
|
<Callout>
|
||||||
|
<Text>{marker.latitude.toFixed(3)}, {marker.longitude.toFixed(3)}</Text>
|
||||||
|
|
||||||
|
|
||||||
|
</Callout>
|
||||||
|
</Marker>
|
||||||
|
</MapView>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
export default HouseLocation;
|
export default HouseLocation;
|
||||||
|
|
Loading…
Reference in New Issue