Icon Stacking - overlaying icons on top of one another

I recently implemented a Google map in my React Native app. However, I'm facing an issue where the icons on the map are overlapping each other instead of being positioned on either side. Despite trying various configurations, the result remains unchanged. Another strange behavior is that the button seems to respond even when not clicked.

The structure of my code includes a container with a MapView nested inside. Here's a snippet:

container: {
    flex: 1,
    flexDirection: 'column'
},
map:{
    height: 90+ "%",
    flexDirection: 'column'
},
profileBtn:{
    position: 'absolute',
    top: 25,
    right: 30,
    width: 25,
    height: 15,
    borderRadius: 25/2,
},
homeBtn:{
    position: 'absolute',
    top: 20,
    left: 5,
    width: 200,
    height: 100,
    borderRadius: 25/2,
},

<MapView
    style={styles.map}
    initialRegion={{
        latitude:this.state.latitude,
        longitude:this.state.longitude,
        latitudeDelta: 0.0043,
        longitudeDelta: 0.0034
    }}
    ref={c => this.mapView = c}
    onPress={this.onMapPress}
    loadingEnabled={true}
>
    <View style ={styles.topMap}>
        <TouchableOpacity
            style={styles.profileBtn}
            onPress={()=>{ this.handleClickProfile() }}
        >
            <Image
                source={profile}
                borderRadius={17}
            />
        </TouchableOpacity>
        <TouchableOpacity
            style={styles.homeBtn}
            onPress={()=>{ this.handleClickFavourite() }}
        >
            <Image
                source={require("./home.png")}
                borderRadius={49}
            />
        </TouchableOpacity>
    </View>
    {markers}

Answer ā„–1

I stumbled upon the reason behind this issue while analyzing the source code at this link. When you instantiate a MapView, it is returned in this manner:

return (
    <AIRMap
        ref={ref => { this.map = ref }}
        {...props}
    />
)

In usual cases of creating custom views, the approach would involve:

return (
    <AIRMap
        ref={ref => { this.map = ref }}
        {...props}
    >
        {children}
    </AIRMap>
)

This might explain why the child elements within your MapView are not rendering as expected. To address this issue, you can relocate the components outside of MapView and enclose everything within a View:

return (
    <View style={{ flex: 1 }}>
        <MapView style={styles.map}>
            {markers}
        </MapView>
        <TouchableOpacity ... />
        <TouchableOpacity ... />
    </View>
)

Keep in mind that each TouchableOpacity must have a position: 'absolute' property to ensure that your MapView occupies the entire screen.

Answer ā„–2

If you're experiencing buttons overlapping each other, it may be due to using position:absolute for the buttons. For marker placement on a map in React Native, consider the following approach:

import { Marker } from 'react-native-maps';

<MapView
  region={this.state.region}
  onRegionChange={this.onRegionChange}
>
  {this.state.markers.map(marker => (
    <Marker
      coordinate={marker.latlng}
      title={marker.title}
      description={marker.description}
    />
  ))}
</MapView>

For more information, visit this link.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering a TypeError while trying to execute a Node.js program

Iā€™m encountering an issue on line 13 while trying to compile my Node.js application: var db = mc.db('course'); ^ TypeError: undefined is not a function at Object.<anonymous> (/app.js:13:13) at Module._compile (module. ...

AngularJS: Initiate a Bootstrap modal upon webpage loading

As I work on designing a web application using AngularJS, I aim to implement the launching of a bootstrap modal upon page load through AngularJS. Here is the structure of my modal: <div class="modal hide fade" id="myModal"> <div class="moda ...

Ideas for showing backslashes in the context of a Cognito filter solution

I need to apply a filtering on Cognito, and the required string format is as follows: "family_name = \"Reddy\"" Currently, I am using `email = "\"${email}"\"` However, when I check the console l ...

How come Redux fails to retain its updated value after adding a new value to the array and refreshing, despite having Redux-persist in place?

Currently, I am implementing redux for managing the state in my application. const addStepReducer = ( stepDetails = [ { stepId: "001", stepTitle: "Step Name", stepDescription:"Step Desc", }, ], ...

Tips for getting information from firestore by implementing a where clause specific to a field within an object?

In my React Native project, I am utilizing Firebase Firestore as the backend database. I have successfully retrieved data from the database using the following code: unsubscribe = firebase.firestore().collection('messages').where('user&apos ...

Ways to extract link value in Angular

Is there a way to extract a value from a link using Angular 4? I have used *ngIf and would like to display a div based on the value within the link. <div *ngIf="obtain the value from the current href"> ...

Troubleshooting issues with Nginx configuration for React Single Page Apps (SPA) hosted on Amazon S3

I'm attempting to configure nginx with single page apps hosted on S3 folders. For master pushes, we utilize the regular CloudFront, S3, and Route 53. However, for branch deployments, we want to avoid using CloudFront for each developer. Our current ap ...

Steps for making a grid within a bootstrap 3 modal

I am new to HTML and CSS I'm working on creating a modal content similar to this: https://ibb.co/RvrhmRs Most of the work is done, but my modal currently looks like this: https://ibb.co/1zG0y2t I just need help arranging an icon next to the text. ...

Is it possible to insert clickable links within the content of a Twilio text message?

Currently, I am utilizing Twilio and Express to send programmable SMSs to the users of my web application. I'm curious if it's possible to include hyperlinks within the body of these text messages. Is there a method to achieve this? I have attem ...

Obtain information from a GET request

When I make a call to my API using the web browser, I receive the following response: {"statusCode": 200, "body": "\"Greetings from AWS Lambda!\""} But now I'm facing difficulty displaying the body content using Axios. Can you identify wha ...

The Android WebView experiencing issues with the functionality of the Hamburger Menu

I'm facing an unusual issue with the Android WebView in my app. The hamburger menu on my website works perfectly fine on my mobile browser, but when I try to open it in the Android WebView, it does not fully expand to show the menu items. I have trie ...

The event listener continues to throw an error when attempting to play audio

I'm encountering an issue with triggering audio in my window's load listener function. var audio = new Audio(); audio.src = "assets/silence.mp3"; audio.load(); document.getElementById("body").addEventListener( 'touchstart', functio ...

When setting the margin to auto, it perfectly centers elements on servers and IE, but on Chrome off the server, it appears to be aligned to the

There seems to be an issue with the display of my page in Chrome - it starts at the middle and ends on the right side. However, when I view it on my server or try it on Internet Explorer 11, it appears centered. Why is that? This problem only arose after ...

Looping through elements with jQuery's `each` method within another `

When using div containers in my code, I wanted to loop over them and then iterate through the items within each container. Instead of $('.stackContainer .stackItem').each(, I was looking for a solution like this: // setup stacks $('.stackC ...

When using the <object> tag, it may not always render at 100% height as intended

Application Inquiry I am seeking assistance with a web page that features a title, and a sticky menu bar at the top, allowing the rest of the space for displaying content. When a menu item is clicked, the objective is to load a page in the content at full ...

The action you're trying to perform is not permitted - Next.js 13 Stripe Payment

I have been attempting to incorporate the Stripe payment gateway into my Next.js application. Despite following their documentation, I am encountering obstacles. How can I address the following error: 405 (Method Not Allowed) CheckForm.js // components ...

Adjust the formatDate function in the Material UI datepicker

I recently implemented the material-ui datepicker component with redux form and it's been working great. However, I have encountered a minor issue. Whenever I change the date, it displays in the input field as yyyy-mm-dd format. I would like it to app ...

Combining various types of media stylesheets with a print stylesheet

I'm struggling with a school assignment that is asking me to compare two different ways of linking a print stylesheet with another stylesheet in HTML. The assignment requires me to explain when each technique would be appropriate: <link rel="style ...

Solving required packages in Express server

I am encountering difficulties with resolving dependencies on my express server. Below is the structure of my project: Calculator --dist ----app -------calculator.js -------server.js --node_modules --src ----app --------calculator.js --------server.js -- ...

What is the best way to position a search icon on the right side using CSS?

I am trying to figure out how to display a search icon image on the right side using CSS, but so far I have been unsuccessful. Here is the code that I have: The CSS code: .search { background: url(../images/icons/search.png) no-repeat; display:in ...