首页 文章

标记不能在MapView上使用Expo进行渲染

提问于
浏览
0

我正在使用Expo和React Native渲染 MapView 并尝试显示一些基本的 Markers ,但是我甚至无法显示默认值 .

下面是传递给全局状态 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
        }
    }
];

以下是我渲染实际 MapView 的代码 . 请注意 MapView 呈现正常,但 Markers 本身不会出现 .

// 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
    }
});

我查看了文档和其他StackOverflow帖子,我无法弄清楚它为什么不呈现 .

我错过了一些明显的东西吗提前致谢 .

1 回答

  • 1

    韦尔普 . 这很尴尬 .

    事实证明我确实错过了一些明显的东西 .

    我翻了经度和纬度值 . 哇 .

    这是它应该看起来的样子,它现在渲染得很好 .

    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
            }
        }
    ];
    

    超级沮丧浪费5个小时,我确信我已经检查过了 . 但是,嘿,如果有其他人遇到这个...双,TRIPLE检查你是否正在插入正确的lat / lng .

相关问题