Маркеры не отображаются на MapView с Expo
Я использую 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
}
});
Я просмотрел документы и другие сообщения Stackru и не могу понять, почему он не будет отображаться.
Я что-то упускаю из виду? Заранее спасибо.
1 ответ
Welp. Это раздражительно.
Оказывается, я что- то упустил очевидное.
Я перевернул значения долготы и широты. Вот это да.
Вот как он ДОЛЖЕН выглядеть, и теперь он выглядит хорошо.
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+ часов, и я был уверен, что проверил это. Но, эй, если кто-то еще столкнется с этим... дважды, ТРАЙПЛ, проверьте, что вы подключаете правильный широта / долгота.