Markers not rendering on MapView

I’m using Expo SDK 24.0 to render a MapView and trying to display some basic Markers, however I can’t even get the default ones to display.

Below is the data that is being passed to the global state of sites :

const sampleSiteMarkers = [
    {
        id: 1,
        title: 'Twin Lakes Hidden Spot',
        description: 'Beautiful view of Twin Lakes off this hidden forest road.',
        coordinate: {
            latitude: -106.391015,
            longitude: 39.085855
        }
    },
    {
        id: 2,
        title: 'Lily Lake',
        description: 'Nice view of the lilypads in this secluded spot, but a pretty tough road to reach it.',
        coordinate: {
            latitude: -106.368051,
            longitude: 39.351661
        }
    },
    {
        id: 3,
        title: 'Slide Lake',
        description: 'Pretty riverside camping, but a REALLY nasty road to get there.',
        coordinate: {
            latitude: -106.389204,
            longitude: 39.372171
        }
    }
];

And below is my code to render the actual MapView. Note that the MapView renders fine, but the Markers themselves do not appear.

// 3rd party libraries - core
import React from 'react';
import {View, Text, StyleSheet} from 'react-native';
import {MapView} from 'expo';

const {Marker} = MapView;
// 3rd party libraries - additional
import _ from 'lodash';


const SearchMap = ({mapLoaded, lastKnownRegion, updateRegion, sites}) => {
    const {fillScreen} = styles;

    const renderSites = () => {
      // sites I showed at the top of this issue come in fine from  props
        const renderedSites = _.map(sites, site => {
            const {title, description, coordinate, id} = site;

            return (
                <Marker
                    key={id}
                    title={title}
                    description={description}
                    coordinate={coordinate}
                />
            );
        });

        // if I inspect renderedSites, I see the Marker element, but it doesn't render
        return renderedSites;
    };

    const renderMap = () => {
        return (
            <MapView
                style={fillScreen}
                initialRegion={lastKnownRegion}
                onRegionChangeComplete={updateRegion}
                rotateEnabled={false}
            >

                {renderSites()}

            </MapView>
        )
    };

    return (
        <View style={fillScreen}>
            {renderMap()}
        </View>
    );

};

const styles = StyleSheet.create({
    fillScreen: {
        flex: 1
    }
});

I’ve looked at the react-native-maps, docs the posts here on Expo Forums, StackOverflow posts, and I can’t figure out why it won’t render.

Am I missing something obvious? Thanks in advance.

Welp. This is embarrassing.

Turns out I did miss something obvious.

I had the longitude and latitude values flipped. Wow.

Here’s how it SHOULD have looked, and it now renders fine.

const sampleSiteMarkers = [
    {
        id: 1,
        title: 'Twin Lakes Hidden Spot',
        description: 'Beautiful view of Twin Lakes off this hidden forest road.',
        coordinate: {
            longitude: -106.391015,
            latitude: 39.085855
        }
    },
    {
        id: 2,
        title: 'Lily Lake',
        description: 'Nice view of the lilypads in this secluded spot, but a pretty tough road to reach it.',
        coordinate: {
            longitude: -106.368051,
            latitude: 39.351661
        }
    },
    {
        id: 3,
        title: 'Slide Lake',
        description: 'Pretty riverside camping, but a REALLY nasty road to get there.',
        coordinate: {
            longitude: -106.389204,
            latitude: 39.372171
        }
    }
];

Super frustrating waste of 5+ hours, and I was sure that I had checked that. But, hey, if anyone else runs into this… double, TRIPLE check that you’re plugging in the right lat/lng.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.