react-native-maps#Marker TypeScript Examples
The following examples show how to use
react-native-maps#Marker.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MapModal.tsx From hamagen-react-native with MIT License | 6 votes |
MapModal = () => {
const dispatch = useDispatch();
const {
showMap: { visible, region, properties },
} = useSelector<Store, GeneralReducer>(state => state.general);
const {
strings: {
scanHome: { inDate, fromHour },
},
} = useSelector<Store, LocaleReducer>(state => state.locale);
const [date, hour] = useMemo(() => {
const time = moment(properties?.fromTime);
return [time.format('DD.MM.YY'), time.format('HH:mm')];
}, [properties?.fromTime]);
return (
<Modal visible={visible} animationType="slide">
<HeaderButton type="close" onPress={() => dispatch({ type: HIDE_MAP_MODAL })} />
<View style={styles.headerContainer}>
<Icon source={require('../../../assets/main/exposuresSmall.png')} width={27} height={17} customStyles={styles.headerIcon} />
<Text bold style={styles.place} numberOfLines={20}>{properties?.Place || ''}</Text>
<Text style={styles.aroundTime}>{`${inDate} ${date} ${fromHour} ${hour}`}</Text>
</View>
<MapView
style={styles.mapStyle}
region={region}
>
<Marker
coordinate={region}
image={require('../../../assets/main/mapMarker.png')}
/>
</MapView>
</Modal>
);
}
Example #2
Source File: index.tsx From NextLevelWeek with MIT License | 6 votes |
SelectMapPosition: React.FC = () => {
const navigation = useNavigation();
const [position, setPosition] = useState({ latitude: 0, longitude: 0 });
function handleNextStep() {
navigation.navigate('OrphanageData', { position });
}
function handleSelectMapPosition(e: MapEvent) {
setPosition(e.nativeEvent.coordinate);
}
return (
<Container>
<Map
initialRegion={{
latitude: -5.8045832,
longitude: -35.1972851,
latitudeDelta: 0.060,
longitudeDelta: 0.060,
}}
onPress={handleSelectMapPosition}
>
{position.longitude !== 0 && (
<Marker
icon={mapMarkerImg}
coordinate={{ latitude: position.latitude, longitude: position.longitude }}
/>
)}
</Map>
{position.longitude !== 0 && (
<NextButton onPress={handleNextStep}>
<NextButtonText>Próximo</NextButtonText>
</NextButton>
)}
</Container>
);
}
Example #3
Source File: SelectMapPosition.tsx From happy with MIT License | 5 votes |
export default function SelectMapPosition() {
const navigation = useNavigation();
const [position, setPosition] = useState({ latitude: 0, longitude: 0});
function handleNextStep() {
navigation.navigate('OrphanageData', { position });
}
function handleSelectMapPosition(event: MapEvent) {
setPosition(event.nativeEvent.coordinate);
}
return (
<View style={styles.container}>
<MapView
initialRegion={{
latitude: -27.2092052,
longitude: -49.6401092,
latitudeDelta: 0.008,
longitudeDelta: 0.008,
}}
style={styles.mapStyle}
onPress={handleSelectMapPosition}
>
{position.latitude !== 0 && (
<Marker
icon={mapMarkerImg}
coordinate={{ latitude: position.latitude, longitude: position.longitude }}
/>
)}
</MapView>
{position.latitude !== 0 && (
<RectButton style={styles.nextButton} onPress={handleNextStep}>
<Text style={styles.nextButtonText}>Próximo</Text>
</RectButton>
)}
</View>
)
}
Example #4
Source File: OrphanagesMap.tsx From nlw-03-omnistack with MIT License | 5 votes |
export default function OrphanagesMap() {
const navigation = useNavigation();
function handleNavigateToCreateOrphanage() {
navigation.navigate('SelectMapPosition');
}
function handleNavigateToOrphanageDetails() {
navigation.navigate('OrphanageDetails');
}
return (
<View style={styles.container}>
<MapView
provider={PROVIDER_GOOGLE}
initialRegion={{
latitude: -27.2092052,
longitude: -49.6401092,
latitudeDelta: 0.008,
longitudeDelta: 0.008,
}}
style={styles.mapStyle}
>
<Marker
icon={mapMarkerImg}
calloutAnchor={{ x: 2.7, y: 0.8 }}
coordinate={{
latitude: -27.2092052,
longitude: -49.6401092
}}
>
<Callout tooltip={true} onPress={handleNavigateToOrphanageDetails}>
<View style={styles.calloutContainer}>
<Text style={styles.calloutText}>Lar das meninas</Text>
</View>
</Callout>
</Marker>
</MapView>
<View style={styles.footer}>
<Text style={styles.footerText}>2 orfanatos encontrados</Text>
<RectButton style={styles.createOrphanage} onPress={handleNavigateToCreateOrphanage}>
<Feather name="plus" size={20} color="#FFF" />
</RectButton>
</View>
</View>
);
}
Example #5
Source File: OrphanageDetails.tsx From nlw-03-omnistack with MIT License | 5 votes |
export default function OrphanageDetails() {
return (
<ScrollView style={styles.container}>
<View style={styles.imagesContainer}>
<ScrollView horizontal pagingEnabled>
<Image style={styles.image} source={{ uri: 'https://fmnova.com.br/images/noticias/safe_image.jpg' }} />
<Image style={styles.image} source={{ uri: 'https://fmnova.com.br/images/noticias/safe_image.jpg' }} />
<Image style={styles.image} source={{ uri: 'https://fmnova.com.br/images/noticias/safe_image.jpg' }} />
</ScrollView>
</View>
<View style={styles.detailsContainer}>
<Text style={styles.title}>Orf. Esperança</Text>
<Text style={styles.description}>Presta assistência a crianças de 06 a 15 anos que se encontre em situação de risco e/ou vulnerabilidade social.</Text>
<View style={styles.mapContainer}>
<MapView
initialRegion={{
latitude: -27.2092052,
longitude: -49.6401092,
latitudeDelta: 0.008,
longitudeDelta: 0.008,
}}
zoomEnabled={false}
pitchEnabled={false}
scrollEnabled={false}
rotateEnabled={false}
style={styles.mapStyle}
>
<Marker
icon={mapMarkerImg}
coordinate={{
latitude: -27.2092052,
longitude: -49.6401092
}}
/>
</MapView>
<View style={styles.routesContainer}>
<Text style={styles.routesText}>Ver rotas no Google Maps</Text>
</View>
</View>
<View style={styles.separator} />
<Text style={styles.title}>Instruções para visita</Text>
<Text style={styles.description}>Venha como se sentir a vontade e traga muito amor e paciência para dar.</Text>
<View style={styles.scheduleContainer}>
<View style={[styles.scheduleItem, styles.scheduleItemBlue]}>
<Feather name="clock" size={40} color="#2AB5D1" />
<Text style={[styles.scheduleText, styles.scheduleTextBlue]}>Segunda à Sexta 8h às 18h</Text>
</View>
<View style={[styles.scheduleItem, styles.scheduleItemGreen]}>
<Feather name="info" size={40} color="#39CC83" />
<Text style={[styles.scheduleText, styles.scheduleTextGreen]}>Atendemos fim de semana</Text>
</View>
</View>
<RectButton style={styles.contactButton} onPress={() => {}}>
<FontAwesome name="whatsapp" size={24} color="#FFF" />
<Text style={styles.contactButtonText}>Entrar em contato</Text>
</RectButton>
</View>
</ScrollView>
)
}
Example #6
Source File: SelectMapPosition.tsx From nlw-03-omnistack with MIT License | 5 votes |
export default function SelectMapPosition() {
const navigation = useNavigation();
const [position, setPosition] = useState({ latitude: 0, longitude: 0});
function handleSelectMapPosition(event: MapEvent) {
setPosition(event.nativeEvent.coordinate);
}
function handleNextStep() {
navigation.navigate('OrphanageData', { position });
}
return (
<View style={styles.container}>
<MapView
initialRegion={{
latitude: -27.2092052,
longitude: -49.6401092,
latitudeDelta: 0.008,
longitudeDelta: 0.008,
}}
onPress={handleSelectMapPosition}
style={styles.mapStyle}
>
{ !!position.latitude && (
<Marker
icon={mapMarkerImg}
coordinate={position}
/>
)}
</MapView>
{ !!position.latitude && (
<RectButton style={styles.nextButton} onPress={handleNextStep}>
<Text style={styles.nextButtonText}>Próximo</Text>
</RectButton>
)}
</View>
)
}
Example #7
Source File: index.tsx From NextLevelWeek with MIT License | 5 votes |
OrphanagesMap: React.FC = () => {
const navigation = useNavigation();
const [orphanages, setOrphanages] = useState<IOrphanage[]>([]);
// Sempre que o usuário sair e voltar para a tela o useFocusEffect é disparado
useFocusEffect(() => {
api.get('/orphanages').then(res => {
setOrphanages(res.data);
});
});
function handleNavigateToOrphanage(id: number) {
navigation.navigate('Orphanage', { id });
}
function handleNavigateToCreateOrphanage() {
navigation.navigate('SelectMapPosition');
}
return (
<MapContainer>
<Map
provider={PROVIDER_GOOGLE}
initialRegion={{
latitude: -5.8026889,
longitude: -35.2224104,
latitudeDelta: 0.060,
longitudeDelta: 0.060,
}}
>
{orphanages.map(orphanage => {
return (
<Marker
key={orphanage.id}
icon={mapMarker}
calloutAnchor={{
x: 2.7,
y: 0.8,
}}
coordinate={{
latitude: orphanage.latitude,
longitude: orphanage.longitude,
}}
>
<Callout tooltip onPress={() => handleNavigateToOrphanage(orphanage.id)}>
<CalloutContainer>
<CalloutText>{orphanage.name}</CalloutText>
</CalloutContainer>
</Callout>
</Marker>
);
})}
</Map>
<Footer>
<FooterText>{orphanages.length} orfanatos encontrados</FooterText>
<CreateOtphanageButton onPress={handleNavigateToCreateOrphanage}>
<Feather name="plus-circle" size={20} color="#FFF" />
</CreateOtphanageButton>
</Footer>
</MapContainer>
);
}
Example #8
Source File: styles.ts From ecoleta with MIT License | 5 votes |
MapMarker = styled(Marker)`
width: 90px;
height: 80px;
`
Example #9
Source File: ExplorePage.tsx From GiveNGo with MIT License | 5 votes |
export default function ExplorePage ({ navigation }: any): React.ReactElement {
const dispatch = useDispatch()
const store = useSelector((state: any) => state.main)
const [region, setRegion] = useState({
latitude: 33.987789,
longitude: -118.470587,
latitudeDelta: 0.005,
longitudeDelta: 0.005,
});
return (
<MapView
style={{ flex: 1 }}
region={region}
onRegionChangeComplete={(region) => setRegion(region)}
>
<Marker
coordinate={{ latitude: 33.987789, longitude: -118.470587 }}
pinColor="blue"
>
<Callout>
<View
style={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-between',
height: 200,
width: 200,
backgroundColor: '#fff',
borderColor: '#eee',
borderRadius: 5,
elevation: 10,
}}
>
<Button
style={{ alignSelf: 'flex-start' }}
appearance="ghost"
// onPress={onPressButton}
>
X
</Button>
<Text style={{ alignSelf: 'center' }}>Flour</Text>
<Button
appearance="outline"
onPress={() =>
navigation.navigate("Give'N'Go", { screen: 'Home' })
}
>
Give
</Button>
</View>
</Callout>
</Marker>
</MapView>
);
}
Example #10
Source File: OrphanagesMap.tsx From happy with MIT License | 5 votes |
export default function OrphanagesMap() {
const [orphanages, setOrphanages] = useState<Orphanage[]>([]);
const navigation = useNavigation();
useFocusEffect(
useCallback(() => {
api.get('orphanages').then(response => {
setOrphanages(response.data);
});
}, [])
);
function handleNavigateToOphanageDetails(id: number) {
navigation.navigate('OrphanageDetails', { id })
}
function handleNavigateToOrphanage() {
navigation.navigate('SelectMapPosition')
}
return (
<View style={styles.container}>
<MapView
provider={PROVIDER_GOOGLE}
style={styles.map}
initialRegion={{
latitude: -27.2092052,
longitude: -49.6401092,
latitudeDelta: 0.008,
longitudeDelta: 0.008,
}}
>
{orphanages.map(orphanage => (
<Marker
key={orphanage.id}
icon={mapMarker}
calloutAnchor={{
x: 2.7,
y: 0.8,
}}
coordinate={{
latitude: orphanage.latitude,
longitude: orphanage.longitude,
}}
>
<Callout tooltip onPress={() => handleNavigateToOphanageDetails(orphanage.id)}>
<View style={styles.calloutContainer}>
<Text style={styles.calloutText}>{orphanage.name}</Text>
</View>
</Callout>
</Marker>
))}
</MapView>
<View style={styles.footer}>
<Text style={styles.footerText}>{orphanages.length} orfanatos encontrados</Text>
<RectButton style={styles.createOrphanageButton} onPress={handleNavigateToOrphanage}>
<Feather name="plus" size={20} color="#fff" />
</RectButton>
</View>
</View>
);
}
Example #11
Source File: index.tsx From NextLevelWeek with MIT License | 4 votes |
Points: React.FC = () => {
const navigation = useNavigation();
const route = useRoute();
const routeParams = route.params as Params;
const [items, setItems] = useState<Item[]>([]);
const [points, setPoints] = useState<Point[]>([]);
const [selectedItems, setSelectedItems] = useState<number[]>([]);
// Salvando a lat e lon do usuário
const [initialPosition, setInitialPosition] = useState<[number, number]>([
0,
0,
]);
useEffect(() => {
api.get("/items").then((res) => {
setItems(res.data);
});
}, []);
/**
* Função para pegar a localização do usuário.
*/
useEffect(() => {
async function LoadPosition() {
// Pedindo ao usuário para autorizar a localização.
const { status } = await Location.requestPermissionsAsync();
// Se não deu a permissão para acessar.
if (status !== "granted") {
Alert.alert(
"Ooooooops...",
"Precisamos de sua permissão para obter a localização."
);
return;
}
const location = await Location.getCurrentPositionAsync();
const { latitude, longitude } = location.coords;
// console.log(latitude, longitude);
setInitialPosition([latitude, longitude]);
}
LoadPosition();
}, []);
/**
* Carregando os Pontos.
*/
useEffect(() => {
api
.get("/points", {
params: {
city: routeParams.city,
uf: routeParams.uf,
items: selectedItems,
},
})
.then((res) => {
setPoints(res.data);
});
}, [selectedItems]);
/**
* Função para voltar na página anterior.
*/
function handleBackToTheFuture() {
navigation.goBack();
}
/**
* Função para navegar quando clicar na imagem no mapa.
*/
function handleNavigateToDetail(id: number) {
navigation.navigate("Detail", { point_id: id });
}
function handleSelectItem(id: number) {
const alreadySelected = selectedItems.findIndex((item) => item === id);
if (alreadySelected >= 0) {
const filteredItems = selectedItems.filter((item) => item !== id);
setSelectedItems(filteredItems);
} else {
setSelectedItems([...selectedItems, id]);
}
}
return (
<SafeAreaView style={{ flex: 1 }}>
<View style={styles.container}>
<TouchableOpacity onPress={handleBackToTheFuture}>
<Icon name="arrow-left" size={20} color="#34cb79" />
</TouchableOpacity>
<Text style={styles.title}>Bem vindo.</Text>
<Text style={styles.description}>
Encontre no mapa um ponto de coleta.
</Text>
<View style={styles.mapContainer}>
{initialPosition[0] !== 0 && (
<MapView
style={styles.map}
initialRegion={{
latitude: initialPosition[0],
longitude: initialPosition[1],
latitudeDelta: 0.014,
longitudeDelta: 0.014,
}}
>
{points.map((point) => (
<Marker
key={String(point.id)}
style={styles.mapMarker}
onPress={() => handleNavigateToDetail(point.id)}
coordinate={{
latitude: point.latitude,
longitude: point.longitude,
}}
>
<View style={styles.mapMarkerContainer}>
<Image
style={styles.mapMarkerImage}
source={{
uri: point.image_url,
}}
/>
<Text style={styles.mapMarkerTitle}>{point.name}</Text>
</View>
</Marker>
))}
</MapView>
)}
</View>
</View>
<View style={styles.itemsContainer}>
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
contentContainerStyle={{ paddingHorizontal: 20 }}
>
{items.map((item) => (
<TouchableOpacity
key={String(item.id)}
style={[
styles.item,
selectedItems.includes(item.id) ? styles.selectedItem : {},
]}
onPress={() => handleSelectItem(item.id)}
activeOpacity={0.6}
>
<SvgUri width={42} height={42} uri={item.image_url} />
<Text style={styles.itemTitle}>{item.title}</Text>
</TouchableOpacity>
))}
</ScrollView>
</View>
</SafeAreaView>
);
}
Example #12
Source File: index.tsx From NextLevelWeek with MIT License | 4 votes |
OrphanageDetails: React.FC = () => {
const route = useRoute();
// console.log(route.params);
const [orphanage, setOrphanage] = useState<IOpharnage>();
// Forçando o params a ter o formato da interface
const params = route.params as IRouteParams;
useEffect(() => {
api.get(`/orphanages/${params.id}`).then(res => {
setOrphanage(res.data);
});
}, [params.id]);
// Fazer tela de loading
if (!orphanage) {
return (
<View>
<Text>Carregando...</Text>
</View>
);
}
// Abrindo o endereço no Google Maps
function handleOpenGoogleMapRoutes() {
Linking.openURL(`https://www.google.com/maps/dir/?api=1&destination=${orphanage?.latitude},${orphanage?.longitude}`);
}
return (
<Container>
<ImagesContainer>
<ScrollView horizontal pagingEnabled>
{orphanage.images.map(image => {
return (
<OrphanageImage
key={image.id}
source={{ uri: image.url }}
/>
);
})}
</ScrollView>
</ImagesContainer>
<DetailsContainer>
<Title>{orphanage.name}</Title>
<Description>{orphanage.about}</Description>
<MapContainer>
<Map
initialRegion={{
latitude: orphanage.latitude,
longitude: orphanage.longitude,
latitudeDelta: 0.008,
longitudeDelta: 0.008,
}}
zoomEnabled={false}
pitchEnabled={false}
scrollEnabled={false}
rotateEnabled={false}
>
<Marker
icon={mapMarkerImg}
coordinate={{
latitude: orphanage.latitude,
longitude: orphanage.longitude,
}}
/>
</Map>
<RoutesButtonContainer onPress={handleOpenGoogleMapRoutes}>
<RoutesText>Ver rotas no Google Maps</RoutesText>
</RoutesButtonContainer>
</MapContainer>
<Separator />
<Title>Instruções para visita</Title>
<Description>{orphanage.instructions}</Description>
<ScheduleContainer>
<ScheduleItemClock>
<Feather name="clock" size={40} color="#2AB5D1" />
<ScheduleText>{orphanage.opening_hours}</ScheduleText>
</ScheduleItemClock>
{
orphanage.open_on_weekends ? (
<ScheduleItemInfo>
<Feather name="info" size={40} color="#39cc83" />
<ScheduleText style={{ color: '#37c77f' }}>
Atendemos fim de semana
</ScheduleText>
</ScheduleItemInfo>
) : (
<ScheduleItemInfoRed>
<Feather name="info" size={40} color="#ff669d" />
<ScheduleText style={{ color: '#ff669d' }}>
Não atendemos fim de semana
</ScheduleText>
</ScheduleItemInfoRed>
)
}
</ScheduleContainer>
<ContactButton>
<FontAwesome name="whatsapp" size={24} color="#fff" />
<ContactButtonText>Entrar em contato</ContactButtonText>
</ContactButton>
</DetailsContainer>
</Container>
);
}
Example #13
Source File: index.tsx From nlw-ecoleta with MIT License | 4 votes |
Points = () => {
const [items, setItems] = useState<Item[]>([]);
const [points, setPoints] = useState<Point[]>([]);
const [selectedItems, setSelectedItems] = useState<number[]>([]);
const [initialPosition, setInitialPosition] = useState<[number, number]>([0, 0]);
const navigation = useNavigation();
const route = useRoute();
const routeParams = route.params as Params;
useEffect(() => {
async function loadPosition(){
const { status } = await Location.requestPermissionsAsync();
if(status !== 'granted') {
Alert.alert('Oooops...', 'Precisamos da sua permissão para obter a localização');
return;
}
const location = await Location.getCurrentPositionAsync();
const { latitude, longitude } = location.coords;
setInitialPosition([
latitude,
longitude
])
}
loadPosition();
}, []);
useEffect(() => {
api.get('items').then(response => {
console.log(response.data);
setItems(response.data);
});
}, []);
useEffect(() => {
api.get('points', {
params: {
city: routeParams.city,
uf: routeParams.uf,
items: selectedItems
}
}).then(response => {
console.log(response.data);
setPoints(response.data);
})
}, [selectedItems]);
function handleNavigateBack() {
navigation.goBack();
}
function handleNavigateToDetail(id: number) {
navigation.navigate('Detail', { point_id: id });
}
function handleSelectItem(id: number) {
const alreadySelected = selectedItems.findIndex(item => item === id);
if (alreadySelected >= 0) {
const filteredItems = selectedItems.filter(item => item !== id);
setSelectedItems(filteredItems);
}
else {
setSelectedItems([ ...selectedItems, id ]);
}
}
return (
<SafeAreaView style={{ flex: 1 }}>
<View style={styles.container}>
<TouchableOpacity onPress={handleNavigateBack}>
<Icon name="arrow-left" size={20} color="#34cb79" />
</TouchableOpacity>
<Text style={styles.title}>Bem vindo.</Text>
<Text style={styles.description}>Encontre no mapa um ponto de coleta.</Text>
<View style={styles.mapContainer}>
{ initialPosition[0] !== 0 && (
<MapView
style={styles.map}
initialRegion={{
latitude: initialPosition[0],
longitude: initialPosition[1],
latitudeDelta: 0.014,
longitudeDelta: 0.014,
}}
>
{points.map(point => (
<Marker
key={String(point.id)}
style={styles.mapMarker}
onPress={() => handleNavigateToDetail(point.id)}
coordinate={{
latitude: point.latitude,
longitude: point.longitude,
}}
>
<View style={styles.mapMarkerContainer}>
<Image style={styles.mapMarkerImage} source={{ uri: point.image_url }} />
<Text style={styles.mapMarkerTitle}>{point.name}</Text>
</View>
</Marker>
))}
</MapView>
) }
</View>
</View>
<View style={styles.itemsContainer}>
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
contentContainerStyle={{ paddingHorizontal: 20 }}
>
{items.map(item => (
<TouchableOpacity
key={String(item.id)}
style={[
styles.item,
selectedItems.includes(item.id) ? styles.selectedItem : {}
]}
onPress={() => handleSelectItem(item.id)}
activeOpacity={0.6}
>
<SvgUri width={42} height={42} uri={item.image_url} />
<Text style={styles.itemTitle}>{item.title}</Text>
</TouchableOpacity>
))}
</ScrollView>
</View>
</SafeAreaView>
);
}
Example #14
Source File: index.tsx From lets-fork-native with MIT License | 4 votes |
export default function Details(props: Props): React.ReactElement {
const headerHeight = useHeaderHeight()
const { restaurant: defaultRestaurant, photos } = props
const [restaurant, setRestaurant] = React.useState(defaultRestaurant)
React.useEffect(() => {
const fetchData = async (): Promise<void> => {
// More details about the restaurant can be fetched from
// the server. This can be triggered off a feature flag in the future.
// For the time being this saves on api requests to yelp.
if (false) { // eslint-disable-line
try {
const rest = await getRestaurant(defaultRestaurant.id)
setRestaurant({
...rest,
...defaultRestaurant,
})
} catch (err) {
console.log(err)
}
} else {
setRestaurant(defaultRestaurant)
}
}
fetchData()
}, [defaultRestaurant])
const imageHeight = env.ADS
? height - headerHeight - 50
: height - headerHeight
const images = [(
<Image
key={restaurant.image_url}
style={{
...styles.image,
height: imageHeight,
}}
source={{ uri: restaurant.image_url, cache: 'force-cache' }}
/>
)]
if (restaurant.photos?.length) {
restaurant.photos.forEach((url) => {
if (url !== restaurant.image_url) {
images.push(
<Image
key={url}
style={{
...styles.image,
height: imageHeight,
}}
source={{ uri: url, cache: 'force-cache' }}
/>,
)
}
})
}
return (
<View
style={{
...styles.container,
minHeight: (height - headerHeight) * 0.8,
}}
>
{
photos ? (
<ScrollView
horizontal
alwaysBounceHorizontal={false}
showsHorizontalScrollIndicator
scrollEventThrottle={10}
pagingEnabled
onScroll={
Animated.event(
[{ nativeEvent: { contentOffset: { x: new Animated.Value(0) } } }],
{ useNativeDriver: true },
)
}
>
{images}
</ScrollView>
) : null
}
<View>
<Text style={[styles.text, styles.name]}>{restaurant.name}</Text>
<View style={styles.rating}>
<Rating rating={restaurant.rating} size="sm" />
<Text style={styles.text}>{`• ${restaurant.review_count} reviews`}</Text>
</View>
<Text
style={styles.text}
>
{
restaurant.price
? `${restaurant.price} • ${restaurant?.categories?.map((c) => c.title).join(', ')}`
: restaurant?.categories?.map((c) => c.title).join(', ')
}
</Text>
{ restaurant?.transactions?.length
? (
<Text style={styles.text}>
{restaurant.transactions.map((tran) => `${tran[0].toUpperCase()}${tran.replace('_', ' ').substring(1)}`).join(' • ')}
</Text>
) : null}
</View>
<View style={styles.section}>
<TouchableOpacity onPress={(): void => call(restaurant.display_phone)}>
<MaterialIcons name="phone" size={32} />
</TouchableOpacity>
<TouchableOpacity onPress={(): Promise<any> => Linking.openURL(restaurant.url)}>
<FontAwesome name="yelp" size={32} color={colors.yelpRed} />
</TouchableOpacity>
</View>
{
restaurant?.coordinates?.latitude && restaurant?.coordinates?.longitude
? (
<View style={styles.mapContainer}>
<MapView
region={{
latitude: restaurant.coordinates.latitude,
longitude: restaurant.coordinates.longitude,
latitudeDelta: 0.005,
longitudeDelta: 0.05,
}}
style={styles.map}
rotateEnabled={false}
scrollEnabled={false}
zoomEnabled={false}
>
<Marker
coordinate={{
latitude: restaurant.coordinates.latitude,
longitude: restaurant.coordinates.longitude,
}}
title={restaurant.name}
/>
</MapView>
</View>
) : null
}
<TouchableOpacity
style={styles.section}
onPress={(): void => {
const url = Platform.select({
ios: `maps:0,0?q=${restaurant.coordinates.latitude},${restaurant.coordinates.longitude}`,
android: `geo:0,0?q=${restaurant.coordinates.latitude},${restaurant.coordinates.longitude}`,
})
if (url) {
Linking.openURL(url)
}
}}
>
<Text style={styles.directionText}>Get Directions</Text>
<MaterialIcons name="directions" size={32} />
</TouchableOpacity>
{
restaurant.hours
? <Hours hours={restaurant.hours} />
: null
}
</View>
)
}
Example #15
Source File: index.tsx From nlw-01-omnistack with MIT License | 4 votes |
Points = () => {
const [items, setItems] = useState<Item[]>([]);
const [points, setPoints] = useState<Point[]>([]);
const [selectedItems, setSelectedItems] = useState<number[]>([]);
const [initialPosition, setInitialPosition] = useState<[number, number]>([0, 0]);
const navigation = useNavigation();
const route = useRoute();
const routeParams = route.params as Params;
useEffect(() => {
async function loadPosition() {
const { status } = await Location.requestPermissionsAsync();
if (status !== 'granted') {
Alert.alert('Oooops...', 'Precisamos de sua permissão para obter a localização');
return;
}
const location = await Location.getCurrentPositionAsync();
const { latitude, longitude } = location.coords;
console.log(latitude, longitude);
setInitialPosition([
latitude,
longitude
])
}
loadPosition();
}, []);
useEffect(() => {
api.get('items').then(response => {
setItems(response.data);
});
}, []);
useEffect(() => {
api.get('points', {
params: {
city: routeParams.city,
uf: routeParams.uf,
items: selectedItems
}
}).then(response => {
setPoints(response.data);
})
}, [selectedItems]);
function handleNavigateBack() {
navigation.goBack();
}
function handleNavigateToDetail(id: number) {
navigation.navigate('Detail', { point_id: id });
}
function handleSelectItem(id: number) {
const alreadySelected = selectedItems.findIndex(item => item === id);
if (alreadySelected >= 0) {
const filteredItems = selectedItems.filter(item => item !== id);
setSelectedItems(filteredItems);
} else {
setSelectedItems([ ...selectedItems, id ]);
}
}
return (
<>
<View style={styles.container}>
<TouchableOpacity onPress={handleNavigateBack}>
<Icon name="arrow-left" size={20} color="#34cb79" />
</TouchableOpacity>
<Text style={styles.title}>Bem vindo.</Text>
<Text style={styles.description}>Encontre no mapa um ponto de coleta.</Text>
<View style={styles.mapContainer}>
{ initialPosition[0] !== 0 && (
<MapView
style={styles.map}
initialRegion={{
latitude: initialPosition[0],
longitude: initialPosition[1],
latitudeDelta: 0.014,
longitudeDelta: 0.014,
}}
>
{selectedItems[0] !== undefined && (points.map(point => (
<Marker
key={String(point.id)}
style={styles.mapMarker}
onPress={() => handleNavigateToDetail(point.id)}
coordinate={{
latitude: point.latitude,
longitude: point.longitude,
}}
>
<View style={styles.mapMarkerContainer}>
<Image style={styles.mapMarkerImage} source={{ uri: point.image_url }} />
<Text style={styles.mapMarkerTitle}>{point.name}</Text>
</View>
</Marker>
)))}
</MapView>
) }
</View>
</View>
<View style={styles.itemsContainer}>
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
contentContainerStyle={{ paddingHorizontal: 20 }}
>
{items.map(item => (
<TouchableOpacity
key={String(item.id)}
style={[
styles.item,
selectedItems.includes(item.id) ? styles.selectedItem : {}
]}
onPress={() => handleSelectItem(item.id)}
activeOpacity={0.6}
>
<SvgUri width={42} height={42} uri={item.image_url} />
<Text style={styles.itemTitle}>{item.title}</Text>
</TouchableOpacity>
))}
</ScrollView>
</View>
</>
);
}
Example #16
Source File: OrphanageDetails.tsx From happy with MIT License | 4 votes |
export default function OrphanageDetails() {
const route = useRoute();
const [orphanage, setOrphanage] = useState<Orphanage>();
const params = route.params as OrphanageDetailsRouteParams;
useEffect(() => {
api.get(`orphanages/${params.id}`).then(response => {
setOrphanage(response.data);
});
}, [params.id]);
if (!orphanage) {
return (
<View style={styles.container}>
<Text style={styles.description}>Carregando...</Text>
</View>
);
}
function handleOpenGoogleMapRoutes() {
Linking.openURL(`https://www.google.com/maps/dir/?api=1&destination=${orphanage?.latitude},${orphanage?.longitude}`);
}
return (
<ScrollView style={styles.container} showsVerticalScrollIndicator={false}>
<View style={styles.imagesContainer}>
<ScrollView horizontal pagingEnabled showsHorizontalScrollIndicator={false}>
{orphanage.images.map(image => (
<Image
key={image.id}
style={styles.image}
source={{ uri: image.url }}
/>
))}
</ScrollView>
</View>
<View style={styles.detailsContainer}>
<Text style={styles.title}>{orphanage.name}</Text>
<Text style={styles.description}>{orphanage.about}</Text>
<View style={styles.mapContainer}>
<MapView
initialRegion={{
latitude: orphanage.latitude,
longitude: orphanage.longitude,
latitudeDelta: 0.008,
longitudeDelta: 0.008,
}}
zoomEnabled={false}
pitchEnabled={false}
scrollEnabled={false}
rotateEnabled={false}
style={styles.mapStyle}
>
<Marker
icon={mapMarkerImg}
coordinate={{
latitude: orphanage.latitude,
longitude: orphanage.longitude,
}}
/>
</MapView>
<TouchableOpacity onPress={handleOpenGoogleMapRoutes} style={styles.routesContainer}>
<Text style={styles.routesText}>Ver rotas no Google Maps</Text>
</TouchableOpacity>
</View>
<View style={styles.separator} />
<Text style={styles.title}>Instruções para visita</Text>
<Text style={styles.description}>{orphanage.instructions}</Text>
<View style={styles.scheduleContainer}>
<View style={[styles.scheduleItem, styles.scheduleItemBlue]}>
<Feather name="clock" size={40} color="#2AB5D1" />
<Text style={[styles.scheduleText, styles.scheduleTextBlue]}>Segunda à Sexta {orphanage.opening_hours}</Text>
</View>
{orphanage.open_on_weekends ? (
<View style={[styles.scheduleItem, styles.scheduleItemGreen]}>
<Feather name="info" size={40} color="#39CC83" />
<Text style={[styles.scheduleText, styles.scheduleTextGreen]}>Atendemos fim de semana</Text>
</View>
) : (
<View style={[styles.scheduleItem, styles.scheduleItemRed]}>
<Feather name="info" size={40} color="#FF669D" />
<Text style={[styles.scheduleText, styles.scheduleTextRed]}>Não atendemos fim de semana</Text>
</View>
)}
</View>
{/* <RectButton style={styles.contactButton} onPress={() => {}}>
<FontAwesome name="whatsapp" size={24} color="#FFF" />
<Text style={styles.contactButtonText}>Entrar em contato</Text>
</RectButton> */}
</View>
</ScrollView>
)
}
Example #17
Source File: index.tsx From NLW-1.0 with MIT License | 4 votes |
Points: React.FC = () => {
const [items, setItems] = useState<Item[]>([]);
const [points, setPoints] = useState<Point[]>([]);
const [selectedItems, setSelectedItems] = useState<number[]>([]);
const [initialPosition, setInitialPosition] = useState<[number, number]>([
0,
0,
]);
const navigation = useNavigation();
const route = useRoute();
const routeParams = route.params as Params;
useEffect(() => {
async function loadPoints() {
const response = await api.get("/items");
setItems(response.data);
}
loadPoints();
}, []);
useEffect(() => {
async function loadPosition() {
const { status } = await Location.requestPermissionsAsync();
if (status !== "granted") {
Alert.alert(
"Ooooops...",
"Precisamos de sua permissão para obter a localização"
);
return;
}
const location = await Location.getCurrentPositionAsync({
enableHighAccuracy: true,
});
const { latitude, longitude } = location.coords;
setInitialPosition([latitude, longitude]);
}
loadPosition();
});
useEffect(() => {
async function loadPoints() {
const response = await api.get("/points", {
params: {
city: routeParams.city,
uf: routeParams.uf,
items: selectedItems,
},
});
setPoints(response.data);
}
loadPoints();
}, [selectedItems]);
function handleNavigateBack() {
navigation.goBack();
}
function handleNavigateToDetail(id: number) {
navigation.navigate("Detail", { point_id: id });
}
function handleSelectItem(id: number) {
const alreadySelected = selectedItems.findIndex((item) => item === id);
if (alreadySelected >= 0) {
const filteredItems = selectedItems.filter((item) => item !== id);
setSelectedItems(filteredItems);
} else {
setSelectedItems([...selectedItems, id]);
}
}
return (
<>
<View style={styles.container}>
<TouchableOpacity onPress={handleNavigateBack}>
<Icon name="arrow-left" size={20} color="#34cb79" />
</TouchableOpacity>
<Text style={styles.title}>Bem vindo.</Text>
<Text style={styles.description}>
Encontre no mapa um ponto de coleta.
</Text>
<View style={styles.mapContainer}>
{initialPosition[0] !== 0 && (
<MapView
style={styles.map}
initialRegion={{
latitude: initialPosition[0],
longitude: initialPosition[1],
latitudeDelta: 0.014,
longitudeDelta: 0.014,
}}
>
{points.map((point) => (
<Marker
key={String(point.id)}
style={styles.mapMarker}
onPress={() => handleNavigateToDetail(point.id)}
coordinate={{
latitude: point.latitude,
longitude: point.longitude,
}}
>
<View style={styles.mapMarkerContainer}>
<Image
style={styles.mapMarkerImage}
source={{
uri: point.image_url,
}}
/>
<Text style={styles.mapMarkerTitle}>{point.name}</Text>
</View>
</Marker>
))}
</MapView>
)}
</View>
</View>
<View style={styles.itemsContainer}>
<ScrollView
contentContainerStyle={{
paddingHorizontal: 32,
}}
horizontal
showsHorizontalScrollIndicator={false}
>
{items.map((item) => (
<TouchableOpacity
key={String(item.id)}
style={[
styles.item,
selectedItems.includes(item.id) ? styles.selectedItem : {},
]}
onPress={() => handleSelectItem(item.id)}
activeOpacity={0.6}
>
<SvgUri width={42} height={42} uri={item.image_url} />
<Text style={styles.itemTitle}>{item.title}</Text>
</TouchableOpacity>
))}
</ScrollView>
</View>
</>
);
}
Example #18
Source File: index.tsx From ecoleta with MIT License | 4 votes |
Points = () => {
const navigation = useNavigation();
const route = useRoute();
const routeParams = route.params as Params;
const [initialPosition, setInitialPosition] = useState<[number, number]>([
0,
0,
]);
const [items, setItems] = useState<Item[]>([]);
const [points, setPoints] = useState<Point[]>([]);
const [selectedItems, setSelectedItems] = useState<number[]>([]);
useEffect(() => {
async function loadPosition() {
const { status } = await Location.requestPermissionsAsync();
if (status !== 'granted') {
Alert.alert(
'Oops!',
'Precisamos da sua permissão para obter a localização'
);
return;
}
const location = await Location.getCurrentPositionAsync();
const { latitude, longitude } = location.coords;
setInitialPosition([latitude, longitude]);
}
loadPosition();
}, []);
useEffect(() => {
api
.get('/points', {
params: {
city: routeParams.city,
uf: routeParams.uf,
items: selectedItems,
},
})
.then((response) => {
setPoints(response.data);
});
}, [selectedItems]);
useEffect(() => {
api.get('/items').then((response) => {
setItems(response.data);
});
}, []);
function handleSelectItem(id: number) {
const alreadySelected = selectedItems.findIndex((item) => item === id);
if (alreadySelected >= 0) {
const filteredItems = selectedItems.filter((item) => item !== id);
setSelectedItems(filteredItems);
} else {
setSelectedItems([...selectedItems, id]);
}
}
function handleNavigateBack() {
navigation.goBack();
}
function handleNavigateToDetail(id: number) {
navigation.navigate('Detail', { point_id: id });
}
return (
<SafeAreaView style={{ flex: 1 }}>
<View style={styles.container}>
<TouchableOpacity onPress={handleNavigateBack}>
<Feather name="arrow-left" color="#34CB79" size={24} />
</TouchableOpacity>
<Text style={styles.title}>Bem vindo</Text>
<Text style={styles.description}>
Encontre no mapa um pronto de coleta.
</Text>
<View style={styles.mapContainer}>
{initialPosition[0] !== 0 && (
<MapView
style={styles.map}
loadingEnabled={initialPosition[0] === 0}
initialRegion={{
latitude: initialPosition[0],
longitude: initialPosition[1],
latitudeDelta: 0.014,
longitudeDelta: 0.014,
}}
>
{points.map((point) => (
<Marker
key={String(point.id)}
style={styles.mapMarker}
onPress={() => handleNavigateToDetail(point.id)}
coordinate={{
latitude: point.latitude,
longitude: point.longitude,
}}
>
<View style={styles.mapMarkerContainer}>
<Image
style={styles.mapMarkerImage}
source={{
uri: point.image_url,
}}
/>
<Text style={styles.mapMarkerTitle}>{point.name}</Text>
</View>
</Marker>
))}
</MapView>
)}
</View>
</View>
<View style={styles.itemsContainer}>
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
contentContainerStyle={{ paddingHorizontal: 20 }}
>
{items.map((item) => (
<TouchableOpacity
key={String(item.id)}
style={[
styles.item,
selectedItems.includes(item.id) ? styles.selectedItem : {},
]}
onPress={() => handleSelectItem(item.id)}
activeOpacity={0.6}
>
<SvgUri width={42} height={42} uri={item.image_url} />
<Text style={styles.itemTitle}>{item.title}</Text>
</TouchableOpacity>
))}
</ScrollView>
</View>
</SafeAreaView>
);
}
Example #19
Source File: index.tsx From ecoleta with MIT License | 4 votes |
Points = () => {
const [items, setItems] = useState<Item[]>([]);
const [points, setPoints] = useState<Point[]>([]);
const [selectedItems, setSelectedItems] = useState<number[]>([]);
const [initialPosition, setInitialPosition] = useState<[number, number]>([0, 0]);
const navigation = useNavigation();
const route = useRoute();
const routeParams = route.params as Params;
useEffect(() => {
async function loadPosition() {
const { status } = await Location.requestPermissionsAsync();
if (status !== 'granted') {
Alert.alert('Ooops...', 'Precisamos de sua permissão para obter a localização.');
return;
}
const location = await Location.getCurrentPositionAsync();
const { latitude, longitude } = location.coords;
setInitialPosition([
latitude,
longitude
]);
}
loadPosition();
}, []);
useEffect(() => {
api.get('items').then(response => {
setItems(response.data);
});
}, []);
useEffect(() => {
api.get('points', {
params: {
city: routeParams.city,
uf: routeParams.uf,
items: selectedItems
}
}).then(response => {
setPoints(response.data);
})
}, [selectedItems])
function handleNavigateBack() {
navigation.goBack();
}
function handeNavigateToDetail(id: number) {
navigation.navigate('Detail', { point_id: id });
}
function handleSelectItem(id: number) {
const alreadSelected = selectedItems.findIndex(item => item === id);
if (alreadSelected >= 0) {
const filteredItems = selectedItems.filter(item => item !== id);
setSelectedItems(filteredItems);
} else {
setSelectedItems([ ...selectedItems, id]);
}
}
return (
<>
<View style={styles.container}>
<TouchableOpacity onPress={handleNavigateBack}>
<Icon name="arrow-left" size={20} color="#34cb79" />
</TouchableOpacity>
<Text style={styles.title}>Bem vindo.</Text>
<Text style={styles.description}>Encontre no mapa um ponto de coleta.</Text>
<View style={styles.mapContainer}>
{ initialPosition[0] !== 0 && (
<MapView
style={styles.map}
initialRegion={{
latitude: initialPosition[0],
longitude: initialPosition[1],
latitudeDelta: 0.014,
longitudeDelta: 0.014,
}}
>
{points.map(point => (
<Marker
key={String(point.id)}
style={styles.mapMarker}
onPress={() => handeNavigateToDetail(point.id)}
coordinate={{
latitude: point.latitude,
longitude: point.longitude,
}}
>
<View style={styles.mapMarkerContainer}>
<Image style={styles.mapMarkerImage} source={{ uri: point.image_url }} />
<Text style={styles.mapMarkerTitle}>{point.name}</Text>
</View>
</Marker>
))}
</MapView>
) }
</View>
</View>
<View style={styles.itemsContainer}>
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
contentContainerStyle={{ paddingHorizontal: 20 }}
>
{items.map(item => (
<TouchableOpacity
key={String(item.id)}
style={[
styles.item,
selectedItems.includes(item.id) ? styles.selectedItem : {}
]}
onPress={() => handleSelectItem(item.id)}
activeOpacity={0.6}
>
<SvgUri width={42} height={42} uri={item.image_url} />
<Text style={styles.itemTitle}>{item.title}</Text>
</TouchableOpacity>
))}
</ScrollView>
</View>
</>
);
}