我正在使用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帖子,我无法弄清楚它为什么不呈现。
我错过了一些明显的东西吗提前致谢。
韦尔普。这很尴尬。
原来我确实错过了一些明显的东西。
我翻了经度和纬度值。哇。
这是它应该看起来的样子,它现在渲染得很好。
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。