How to slide down a View in react native - react-native

Hi I am new to react native
I have mapview and FlatList in my screen like shown in the below image.
Now I want Mapview to be expanded when i click on it , like the below image
Here is my code
import React, { Component } from 'react';
import MapView, { PROVIDER_GOOGLE, Marker } from 'react-native-maps';
import { View, StyleSheet, Text, TouchableOpacity, Animated, Image } from 'react-native';
import { Actions } from 'react-native-router-flux';
import DoctorsList from './DoctorsList';
import colors from '../styles/colors';
var isHidden = true;
export default class FindDoctorMaps extends Component {
constructor(props) {
super(props);
this.state = {
bounceValue: new Animated.Value(500), //This is the initial position of the subview
buttonText: 'LIST VIEW',
printText: false,
markers: [{
title: 'hello',
coordinates: {
latitude: 17.452,
longitude: 78.3721
},
},
{
title: 'hi',
coordinates: {
latitude: 17.458,
longitude: 78.3731
},
},
{
title: 'gyp',
coordinates: {
latitude: 17.468,
longitude: 78.3631
},
},
{
title: 'nig',
coordinates: {
latitude: 17.568,
longitude: 78.3831
},
},
{
title: 'Yoy',
coordinates: {
latitude: 17.588,
longitude: 78.4831
},
}]
};
}
render() {
return (
<View style={{ flex: 1, backgroundColor: 'white' }} >
<MapView
provider={PROVIDER_GOOGLE}
region={{
latitude: 17.452,
longitude: 78.3721,
latitudeDelta: 0.015,
longitudeDelta: 0.0121,
}}
style={styles.map}
showsUserLocation
followUserLocation
showsMyLocationButton
showsCompass
zoomEnabled
>
{this.state.markers.map(marker => (
<MapView.Marker
coordinate={marker.coordinates}
title={marker.title}
onPress={this.onMarkerPress}
/>
))}
</MapView>
<TouchableOpacity style={styles.filterContainer} onPress={Actions.morefilters}>
<View style={styles.filterStyle}>
<Image style={{ margin: 5 }} source={require('../assets/filters_icon.png')} />
<Text style={{ fontSize: 14, color: colors.darkBlue, fontWeight: 'bold', }}> Filters</Text>
</View>
</TouchableOpacity>
<View>
<TouchableOpacity >
<DoctorsList />
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
map: {
height: 200,
},
textViewStyle: {
fontSize: 14,
color: '#00539d',
fontWeight: 'bold',
margin: 20
},
subView: {
position: 'absolute',
bottom: 0,
left: 0,
right: 0,
backgroundColor: '#FFFFFF',
height: 500,
},
filterContainer: {
top: '20%',
right: 0,
alignSelf: 'flex-end',
position: 'absolute'
},
filterStyle: {
flexDirection: 'row',
backgroundColor: colors.white,
borderRadius: 8,
height: 30,
width: '60%',
alignItems: 'center',
justifyContent: 'center'
}
});
Can any one please help me how to expand Mapview by clicking on it.
or else please share some useful links so that i would be helpful for me

this.state = {
....
showMapFullScreen: false
....
}
render() {
....
<MapView
....
style={height: showMapFullScreen ? "100%" : 200 }
onPress={() => this.setState({ showMapFullScreen : true }) }
....
>
....
<TouchableOpacity
onPress={() => this.setState({ showMapFullScreen : false }) }>
<DoctorsList />
</TouchableOpacity>
.......
}
You can toggle the map height with a flag like shown above. When the user clicks on the map the height becomes full screen when he/she clicks on the list the map's height is reduced and gives space to the list to render.

Related

react-native-maps MapView rotation

I want to rotate the MapView as per the phone rotation. I am not getting a solution in official documentation, so I did a trick to do it by rotating the layout by setting the transform style but I can understand it is not the perfect solution because the labels over the screen also rotating with the layout.
If it is possible by animateCamera, Please suggest me how can I update the code.
I have attached a screenshot of the issue and relevant code block.
import MapView from 'react-native-maps';
import { Bubbles, DoubleBounce } from 'react-native-loader';
class TestPropUpdate extends Component {
constructor(props) {
super(props);
this.state = {
origin: null,
latlong: null,
initialRegion: null,
compasAngle: 0
};
}
componentDidUpdate() {
CompassHeading.start(3, ({ heading, accuracy }) => {
if (this.state.compasAngle !== heading) {
this.setState({ compasAngle: heading })
console.log(heading)
}
CompassHeading.stop();
})
}
getCurrentLocation = () => ({
latitude: this.state.latlong.currentLatitude,
longitude: this.state.latlong.currentLongitude,
latitudeDelta: 0.01,//0.01155,
longitudeDelta: 0.01//0.01155
});
setCurrentLocation = (locationChangedResult) => {
this.setState({
latlong: {
"currentLatitude": locationChangedResult.nativeEvent.coordinate.latitude,
"currentLongitude": locationChangedResult.nativeEvent.coordinate.longitude
}
})
}
render() {
return (
<SafeAreaView style={{ flex: 1, position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, justifyContent: 'center', alignItems: 'center' }}>
{this.state.latlong ?
<MapView
onUserLocationChange={locationChangedResult => this.setCurrentLocation(locationChangedResult)}
region={this.getCurrentLocation()}
style={[
styles.mapStyle,
{
transform: [{ rotate: `${360 - this.state.compasAngle}deg` }],
}
]}
>
</MapView>
: <DoubleBounce />}
</SafeAreaView>
);
}
}
export default TestPropUpdate;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
padding: 10,
alignItems: 'center',
justifyContent: 'center',
},
boldText: {
fontSize: 25,
color: 'red',
marginVertical: 16,
textAlign: 'center'
},
mapStyle: {
position: 'absolute',
width: "200%",
height: "100%",
}
});

How to Overlay selected custom marker in react-native-maps

I use react-native-maps to display an array of positions using custom marker. I want to overlay the selected maker, but did not found the right solution. Using position: 'absolute' for the selected marker changes its position in the map.
Here is the code of the MapView:
<MapView
style={styles.map}
region={region} // initial region is user location if myPosition or coordinates of search
// onRegionChange={onRegionChange}
>
<View style={{position: 'absolute'}}>
{data.map((item) => (
<Marker
onPress={() => handleMarkerPress(item)}
coordinate={{
latitude: item.latitude,
longitude: item.longitude,
}}
// image={require('Resources/geoloc.png')}
// pinColor={item.id === visibleItemId ? 'red' : 'blue'}
key={item.id}>
<MosqueMarquer
mosqueImage={item.images}
itemId={item.id}
visibleItemId={visibleItemId}
distance={item.distance_result}
/>
</Marker>
))}
{isUserGeoLoc ? (
<Marker
coordinate={{
latitude: userLocation.latitude,
longitude: userLocation.longitude,
}}
description={'Your are here'}>
<Image
resizeMode="contain"
source={require('Resources/user_location.png')}
style={{tintColor: '#4280ee', height: 25}}
/>
</Marker>
) : null}
</View>
</MapView>
And here is the custom marker code:
const MosqueMarquer = (props) => {
const relativeStyle =
props.itemId == props.visibleItemId
? {position: 'absolute', tintColor: '#428947', color: '#fff', zIndex: 1}
: {position: null, tintColor: '#fff', color: '#3c423d', zIndex: 0};
return (
<ImageBackground
resizeMode="contain"
source={require('Resources/square_marker.png')}
style={{
...styles.imageBackground,
position: relativeStyle.position,
zIndex: relativeStyle.zIndex,
}}
imageStyle={{tintColor: relativeStyle.tintColor}}>
<Text style={{...styles.text, color: relativeStyle.color}}>
{props.distance}m
</Text>
</ImageBackground>
);
};
export default MosqueMarquer;
const styles = StyleSheet.create({
imageBackground: {
width: 70,
height: 70,
justifyContent: 'center',
alignItems: 'center',
},
text: {
fontSize: common.FONT_SIZE_H38,
},
});
the selected marker in green is under the none selected one:
THANKS
<XMarksTheSpot coordinates={coordinatesOfYOurMarker} center={center} />
XMarksTheSpot ->
import React from 'react';
import PropTypes from 'prop-types';
import { View } from 'react-native';
import { Polygon, Polyline, Marker } from 'react-native-maps';
class XMarksTheSpot extends React.Component {
render() {
return (
<View>
<Polygon
coordinates={this.props.coordinates}
strokeColor="rgba(0, 0, 0, 1)"
strokeWidth={3}
/>
<Polyline
coordinates={[this.props.coordinates[0], this.props.coordinates[2]]}
/>
<Polyline
coordinates={[this.props.coordinates[1], this.props.coordinates[3]]}
/>
<Marker coordinate={this.props.center} />
</View>
);
}
}
XMarksTheSpot.propTypes = {
coordinates: PropTypes.array,
center: PropTypes.object,
zIndex: PropTypes.number,
};
export default XMarksTheSpot;

React native maps jumps back to region on release

I use react-native maps - Mapview in my React Native app. On Android, the code works as expected, the location of the user is used to determine the region. This will be included in this.state.latitude and this.state.longtitude. Only on iOS I have the problem that when I 'scroll' on the map it jumps back to the region after releasing it. If I put the code on initialRegion I end up somewhere in a sea and the user has to scroll indefinitely. Does anybody have experience with this?
after setting code to initialRoute:
The current code:
import React, {Component} from 'react';
import {StyleSheet, Text, View,ScrollView, SafeAreaView, ImageBackground, Button,TouchableOpacity, Alert, Image, Linking, ActivityIndicator} from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome';
import { ListItem, ThemeConsumer } from 'react-native-elements'
import { Marker, PROVIDER_GOOGLE } from "react-native-maps";
//import { ClusterMap } from "react-native-cluster-map";
import MapView from "react-native-map-clustering";
import firebase from 'react-native-firebase';
import Geolocation from '#react-native-community/geolocation';
import LaunchNavigator from 'react-native-launch-navigator';
if(Platform.OS === "android") LaunchNavigator.setGoogleApiKey("API KEY");
class locationScreen extends Component {
constructor(props){
super(props);
this.state = {
cities : [ ],
totalStores: 0,
latitude:0,
longitude: 0,
nearestPlace: null,
}
}
deg2Rad = (deg) => {
return deg * Math.PI / 180;
}
pythagorasEquirectangular = (lat1, lon1, lat2, lon2) => {
lat1 = this.deg2Rad(lat1);
lat2 = this.deg2Rad(lat2);
lon1 = this.deg2Rad(lon1);
lon2 = this.deg2Rad(lon2);
const R = 6371;
const x = (lon2 - lon1) * Math.cos((lat1 + lat2) / 2);
const y = (lat2 - lat1);
const d = Math.sqrt(x * x + y * y) * R;
return d;
}
nearestCity = (latitude, longitude) => {
let mindif = 99999;
let closest;
for (let index = 0; index < this.state.cities.length; index++) {
const dif = this.pythagorasEquirectangular(latitude, longitude, this.state.cities[index].lat,
this.state.cities[index].long);
if (dif < mindif) {
closest = index;
mindif = dif;
}
}
this.setState({
nearestPlace: closest,
})
this.state.cities.forEach(i =>{
if( i.name == this.state.cities[this.state.nearestPlace].name) i.nearest = 1 ;
})
this.setState({
cities: this.state.cities,
})
// this.nearestPlace = closest
// return cities= closest;
}
navigateTo = (item) => {
console.log(item.street);
LaunchNavigator.navigate(item.street + "," + item.zip+ ","+ item.city)
.then(() => console.log("Launched navigator"))
.catch((err) => console.error("Error launching navigator: "+err));
}
setCurrentDirections = () =>{
Geolocation.getCurrentPosition(position => {
this.setState({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
desLat: position.coords.latitude,
desLong: position.coords.longitude,
error: null,
});
console.log("reached function");
console.log("latitude: " + this.state.latitude);
console.log("Longtitude: " + this.state.longitude);
})
}
setNearestonClick= (clickId) =>{
this.state.cities.forEach(i =>{
if( i.name == clickId) i.nearest = 1 ;
})
this.setState({
cities: this.state.cities,
})
}
onItemClickHandler= (url)=>{
Linking.openURL(url)
}
/* PressedLocation = (data) =>{
console.log('location:' + data.lat + 'long ' +data.long );
this.setState({
latitude: data.lat,
longitude: data.long,
error: null,
});
}
*/
markerCliked = (id) =>{
console.log("id is: " + id);
}
latitude= 0;
longitude= 0;
componentDidMount(){
this.setCurrentDirections();
let ref = firebase.database().ref('stores');
ref.on('value' , snapshot =>{
var state = snapshot.val();
this.setState({
cities: state,
totalStores: state.length,
})
this.nearestCity(this.state.latitude, this.state.longitude);
})
}
render(){
const { cities } = this.state;
return(
<ScrollView style={styles.scorllVert}>
<SafeAreaView style={styles.container}>
<View style={styles.headerLeft}>
<TouchableOpacity style={styles.menubar} onPress={this.props.navigation.openDrawer}>
<Icon name="bars" size={24}/>
</TouchableOpacity>
</View>
<View style={styles.headerCenter}>
<Image source={require('./assets/images/all/logo-snackpoint.png')} style={styles.logoSnackpoint} />
</View>
<View style={styles.headerRight}>
<TouchableOpacity style={styles.userIcon}>
<Icon name="user-circle" size={24} onPress={this.props.navigation.openDrawer}/>
</TouchableOpacity>
</View>
</SafeAreaView>
<View style={styles.headerStores}>
<Text style={styles.headerStoresText}>Aantal vestigingen: {this.state.totalStores}</Text>
</View>
<View style={styles.containerContent}>
<View style={styles.page}>
<View style={styles.containerMap}>
<MapView
showsUserLocation={true}
style={{ flex: 1 }}
onClusterPress={() => this.markerCliked()}
region={{
latitude: this.state.latitude,
longitude: this.state.longitude,
latitudeDelta: 0.015,
longitudeDelta: 0.0121
}}
>
{
this.state.cities.map(marker => (
<Marker key={marker.name} coordinate={{latitude: marker.lat, longitude: marker.long}} onPress={() => this.setNearestonClick(marker.name)}/>
))
}
</MapView>
</View>
</View>
<View style={styles.stores}>
{
this.state.cities.sort(function(a, b) {
if(a.nearest) return -1;
if(b.nearest) return 1;
if(a.name.toLowerCase() < b.name.toLowerCase()) return -1;
if(a.name.toLowerCase() > b.name.toLowerCase()) return 1;
return 0;
}).map((marker, i) => (
<TouchableOpacity onPress={() => this.navigateTo(marker)} >
<View style={styles.store}>
<View style={styles.leftcolumn}>
<Text style={styles.storeTitle}>{marker.name}</Text>
<Text>{marker.street}</Text>
<Text>{marker.zip}, {marker.city}</Text>
<Text>Telefoon: {marker.phone}</Text>
</View>
<View style={styles.midcolumn}>
<Text>Ma:</Text>
<Text>Di:</Text>
<Text>Wo:</Text>
<Text>Do:</Text>
<Text>Vr:</Text>
<Text>Za:</Text>
<Text>Zo:</Text>
</View>
<View style={styles.rightcolumn}>
<Text>{marker.monday}</Text>
<Text>{marker.tuesday}</Text>
<Text>{marker.wednesday}</Text>
<Text>{marker.thursday}</Text>
<Text>{marker.friday}</Text>
<Text>{marker.saturday}</Text>
<Text>{marker.sunday}</Text>
</View>
</View>
<View style={{borderBottomColor: '#C8C8C8',borderBottomWidth: 1,}}/>
</TouchableOpacity>
))
}
</View>
</View>
</ScrollView>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
flexWrap: 'wrap',
alignItems: 'flex-start',
marginBottom: 13
},
text:{
color: "#161924",
fontSize: 20,
fontWeight: "500",
},userIcon:{
paddingTop: 22,
paddingRight: 0,
alignItems: 'flex-end',
},
logoSnackpoint:{
width: 180,
height: 52,
marginTop: 12,
},
headerLeft:{
width: '33%',
},
headerCenter:{
width: '30%',
alignItems: 'center',
},
headerRight:{
width: '30%',
},
menubar:{
paddingTop: 22,
paddingLeft: 20
},
containerContent:{
padding: 0,
paddingBottom: 30
},
title:{
fontSize: 35
},
textTitle:{
marginTop: 10,
},
titleRed:{
fontSize: 25,
color: '#CC2929',
marginTop: 30,
marginBottom: 10
},
map: {
flex: 1
},
page: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF"
},
containerMap: {
height: 300,
width: '100%',
backgroundColor: "tomato"
},
headerStores:{
width: '100%',
backgroundColor: '#CD2929',
textAlign: 'center',
paddingTop: 20,
paddingBottom: 20
},
headerStoresText:{
color: 'white',
textAlign: 'center'
},
store:{
flexDirection: 'row',
flexWrap: 'wrap',
alignItems: 'flex-start',
width: '100%',
padding: 20
},
leftcolumn:{
width: "50%",
},
midcolumn:{
width: "20%",
},
rightcolumn:{
width: "30%",
},
storeTitle:{
color: '#CD2929',
fontWeight: "bold",
fontSize: 30
},
hr:{
backgroundColor: 'grey',
padding: 5
}
});
export default locationScreen;
It looks like that there is a problem when setting the region property within the MapView.
From my code, I removed the part that looks like this from the MapView
region=
{{
latitude: this.state.latitude,
longitude: this.state.longitude,
latitudeDelta: 0.015,
longitudeDelta: 0.0121
}}
and I can scroll back again.
But then, you'll have to find a way to set the region, it looks buggy with this component. Especially with class components.
initialRegion is uncontrolled state, the map will only set to the region on initial load, so if you set it before your region is defined it will focus on lat:0, lng: 0 -- out in the ocean. So before you render your map, make sure the region is defined.
region is controlled state, as the map redraws it will use the most recent region definition. If you drag the map, and the region doesn't update doesn't get updated to the new location, the next redraw of the map will go to whatever the region was last defined as. handleRegionChangeComplete can be used to update the region as you move, but you can run into jumpiness if multiple redraws are occurring at the same time.

view layout props is not working properly

import React, { Component } from "react";
import {
Platform,
StyleSheet,
Text,
View,
TouchableOpacity,
Alert,
Image,
Button,
TextInput,
Dimensions
} from "react-native";
import { Dialog } from "react-native-simple-dialogs";
import AsyncStorage from "#react-native-community/async-storage";
import { KeyboardAvoidingView } from "react-native";
import DropdownAlert from "react-native-dropdownalert";
import { BoxShadow } from "react-native-shadow";
import { DrawerActions } from "react-navigation-drawer";
import MapView, { PROVIDER_GOOGLE } from "react-native-maps";
import datum from "./data";
import { Marker } from "react-native-maps";
import Parse from "parse/react-native";
import Geolocation from "react-native-geolocation-service";
import { GooglePlacesAutocomplete } from "react-native-google-places-autocomplete";
const homePlace = {
description: "Home",
geometry: {
location: {
lat: 48.8152937,
lng: 2.4597668
}
}
};
const workPlace = {
description: "Work",
geometry: {
location: {
lat: 48.8496818,
lng: 2.2940881
}
}
};
export default class Home extends React.Component {
constructor(props) {
super(props);
this.state = {
lat: 12.9122536,
long: 80.0987121,
picklat: 12.9122536,
picklong: 80.0987121,
droplat: 12.9202954,
droplong: 80.1026819,
curautostate: "pick",
curautostateplaceholder: "Enter your pick up location",
distance: 0,
windowwidth: Dimensions.get("window").width,
windowheight: Dimensions.get("window").height
};
}
componentDidMount() {
Geolocation.requestAuthorization();
Geolocation.getCurrentPosition(
position => {
this.setState({
lat: position.coords.latitude
});
this.setState({
long: position.coords.longitude
});
this.setState({
picklat: position.coords.latitude
});
this.setState({
picklong: position.coords.longitude
});
this.setState({
droplat: position.coords.latitude
});
this.setState({
droplong: position.coords.longitude
});
},
error => {
Alert.alert(
"Please enable the location service",
error.message,
[
{
text: "OK",
onPress: () => console.log("has to exit")
}
],
{
cancelable: false
}
);
},
{
enableHighAccuracy: true,
timeout: 15000,
maximumAge: 10000
}
);
}
tooglestate = getstate => {
if (getstate == "drop") {
this.setState({
curautostate: "drop"
});
this.setState({
curautostateplaceholder: "Enter your drop location"
});
this.setState({
lat: this.state.droplat,
long: this.state.droplong
});
} else if (getstate == "pick") {
this.setState({
curautostate: "pick"
});
this.setState({
curautostateplaceholder: "Enter your pick location"
});
this.setState({
lat: this.state.picklat,
long: this.state.picklong
});
} else {
}
};
executeautocompleteView = text => {
console.log(text);
};
render() {
return (
<View
style={{
flex: 1,
flexDirection: "column",
backgroundColor: datum.secondaryColor
}}
>
<View
style={{
backgroundColor: "#E8EDF1",
width: "100%",
height: "9%",
top: 0,
zIndex: 1,
shadowColor: datum.secondaryColor,
elevation: 20,
flexDirection: "column"
}}
>
<Image
source={require("./Drawbles/Homeicon.png")}
resizeMode="contain"
style={{
width: "10%",
height: "100%",
alignSelf: "center"
}}
/>
</View>
<MapView
style={styles.map}
initialRegion={{
latitude: this.state.lat,
longitude: this.state.long,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
}}
region={{
latitude: this.state.lat,
longitude: this.state.long,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
}}
>
<Marker
draggable
coordinate={{
latitude: this.state.picklat,
longitude: this.state.picklong
}}
pinColor={"#56954A"}
onDragEnd={e => {
this.setState({
picklat: e.nativeEvent.coordinate.latitude,
picklong: e.nativeEvent.coordinate.longitude,
lat: e.nativeEvent.coordinate.latitude,
long: e.nativeEvent.coordinate.longitude
});
}}
/>
<Marker
draggable
coordinate={{
latitude: this.state.droplat,
longitude: this.state.droplong
}}
pinColor={"#C5441B"}
onDragEnd={e =>
this.setState({
droplat: e.nativeEvent.coordinate.latitude,
droplong: e.nativeEvent.coordinate.longitude,
lat: e.nativeEvent.coordinate.latitude,
long: e.nativeEvent.coordinate.longitude
})
}
/>
</MapView>
<View
style={{
flexDirection: "row",
backgroundColor: datum.secondaryColor,
zIndex: 1,
alignSelf: "center",
top: "10%",
height: this.state.windowheight * 0.07,
width: this.state.windowwidth * 0.9,
shadowColor: datum.secondaryColor,
elevation: 20
}}
>
<TouchableOpacity onPress={() => this.tooglestate("pick")}>
<View
style={{
width: this.state.windowwidth * 0.13,
height: this.state.windowheight * 0.07,
backgroundColor: "#56954A"
}}
/>{" "}
</TouchableOpacity>
<GooglePlacesAutocomplete
placeholder="Search"
minLength={2} // minimum length of text to search
autoFocus={false}
returnKeyType={"search"} // Can be left out for default return key https://facebook.github.io/react-native/docs/textinput.html#returnkeytype
keyboardAppearance={"light"} // Can be left out for default keyboardAppearance https://facebook.github.io/react-native/docs/textinput.html#keyboardappearance
listViewDisplayed="auto" // true/false/undefined
fetchDetails={true}
renderDescription={row => row.description} // custom description render
onPress={(data, details = null) => {
// 'details' is provided when fetchDetails = true
console.log(data, details);
}}
getDefaultValue={() => ""}
query={{
// available options: https://developers.google.com/places/web-service/autocomplete
key: "6Iza4Sy3APa34ewekfaM3yZB-Tt6SNO4",
language: "en", // language of the results
types: "(cities)" // default: 'geocode'
}}
styles={{
textInputContainer: {
width: "100%",
backgroundColor: datum.primaryColor
},
description: {
fontWeight: "bold"
},
textInput: {
backgroundColor: datum.primaryColor
},
predefinedPlacesDescription: {
color: datum.primaryColor
}
}}
currentLocationLabel="Current location"
nearbyPlacesAPI="GooglePlacesSearch" // Which API to use: GoogleReverseGeocoding or GooglePlacesSearch
GoogleReverseGeocodingQuery={
{
// available options for GoogleReverseGeocoding API : https://developers.google.com/maps/documentation/geocoding/intro
}
}
GooglePlacesSearchQuery={{
// available options for GooglePlacesSearch API : https://developers.google.com/places/web-service/search
rankby: "distance",
type: "cafe"
}}
GooglePlacesDetailsQuery={{
// available options for GooglePlacesDetails API : https://developers.google.com/places/web-service/details
fields: "formatted_address"
}}
filterReverseGeocodingByTypes={[
"locality",
"administrative_area_level_3"
]} // filter the reverse geocoding results by types - ['locality', 'administrative_area_level_3'] if you want to display only cities
debounce={200} // debounce the requests in ms. Set to 0 to remove debounce. By default 0ms.
/>
<TouchableOpacity onPress={() => this.tooglestate("drop")}>
<View
style={{
width: this.state.windowwidth * 0.13,
height: this.state.windowheight * 0.07,
backgroundColor: "#C5441B"
}}
/>{" "}
</TouchableOpacity>
</View>
<View
style={{
backgroundColor: datum.secondaryColor,
width: "100%",
height: "9%",
top: "90%",
zIndex: 2,
shadowColor: datum.secondaryColor,
elevation: 20,
flexDirection: "row"
}}
/>
<DropdownAlert ref={ref => (this.dropdown = ref)} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF"
},
welcome: {
fontSize: 20,
textAlign: "center",
margin: 10
},
instructions: {
textAlign: "center",
color: "#333333",
marginBottom: 5
},
map: {
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
zIndex: 2
},
headertext: {
fontSize: 20,
textAlign: "center",
color: datum.secondaryColor,
margin: 10
},
bookingbar: {
flex: 1,
flexDirection: "row",
height: "30%",
width: "100%",
zIndex: 30,
bottom: 0
}
});
I am trying to align the Last view comp to top '90%' but somehow my layout breaks I don't know what went wrong, my black view is supposed to be at the bottom edge of the comp but it slight align up where it suppose to be, I have tried using point/and percentages but nothing seems to work, I don't where is the mistake is that with me or with react native library
You are missing the absolute position property, try this:
<View style={{
backgroundColor: 'blue',
position: 'absolute',
width: '100%',
height: '10%',
top: '90%',
zIndex: 2,
shadowColor: 'black',
elevation: 20,
flexDirection: 'row'
}}/>

How to display a Text outside of a MapView when a Marker is Pressed in react-native-maps

I'm working with react-native-maps. I have created a mapview with multiple markers in it, now I want to show a text outside of mapview when a prticular marker is clicked
it should be like this
Here is my code
import React, { Component } from 'react';
import MapView, { PROVIDER_GOOGLE, Marker } from 'react-native-maps';
import { View, StyleSheet, Text } from 'react-native';
class FindDoctorMaps extends Component {
constructor(props) {
super(props);
this.state = {
markers: [{
title: 'hello',
coordinates: {
latitude: 17.452,
longitude: 78.3721
},
},
{
title: 'hi',
coordinates: {
latitude: 17.458,
longitude: 78.3731
},
},
{
title: 'gyp',
coordinates: {
latitude: 17.468,
longitude: 78.3631
},
},
{
title: 'nig',
coordinates: {
latitude: 17.568,
longitude: 78.3831
},
},
{
title: 'Yoy',
coordinates: {
latitude: 17.588,
longitude: 78.4831
},
}]
};
}
render() {
return (
<View style={{ flex: 1, backgroundColor: 'white' }} >
<MapView
provider={PROVIDER_GOOGLE}
region={{
latitude: 17.452,
longitude: 78.3721,
latitudeDelta: 0.015,
longitudeDelta: 0.0121,
}}
style={styles.map}
showsUserLocation
followUserLocation
showsMyLocationButton
showsCompass
zoomEnabled
>
{this.state.markers.map(marker => (
<MapView.Marker
coordinate={marker.coordinates}
title={marker.title}
/>
))}
</MapView>
<Text style={{ fontSize: 14, color: '#00539d', fontWeight: 'bold', margin: 20 }}>LIST VIEW</Text>
</View>
);
}
}
const styles = StyleSheet.create({
map: {
height: 600,
},
SectionStyle: {
flexDirection: 'row',
backgroundColor: '#fff',
borderWidth: 0.5,
borderColor: '#000',
height: 40,
borderRadius: 5,
margin: 10
},
ImageStyle: {
padding: 10,
margin: 5,
}
});
export default FindDoctorMaps;
can anyone help me to display some text outside of mapview like show in the above image.
Thanks
after some good time I figure it out, you can put two markers together on the same spot, one for the pin and the other with the text:
render() {
let markers = this.state.placesLoaded.map((item, i) => {
return <View key = { i }>
// Default marker img
<MapView.Marker
coordinate={place.coordinates[0]}
title={item.name}/>
// Text component that you want to show
<MapView.Marker coordinate={place.coordinates[0]}>
<Text style={{top: 8}}>{item.name}</Text>
</MapView.Marker>
</View>
return (
<MapView>
{markers}
</MapView>
)
}