Mah*_*our 8 google-maps react-native react-native-android react-native-maps react-native-map-clustering
我在地图上加载了大约 2000 个标记。它在前几秒钟工作正常,但随后急剧减速。要修复它,我需要清除应用程序数据,然后它只能像以前一样工作几秒钟。
const mapMarkers = [
{id: 1, code: "603778", lat: 35.761791, lng: 51.389438},
{id: 2, code: "788621", lat: 35.712278, lng: 51.361785},
{id: 3, code: "129667", lat: 35.674757, lng: 51.485328},
{id: 4, code: "999646", lat: 35.772885, lng: 51.446735},
{id: 5, code: "111524", lat: 35.755656, lng: 51.446774},
//...
];
let markers = mapMarkers.map(marker => {
return (<Marker
key={marker.code}
coordinate={{latitude: marker.lat, longitude: marker.lng}}
image={require('./images/markers.png')}
onPress={() => console.log("pressed")}
/>)
});
Run Code Online (Sandbox Code Playgroud)
我测试了emulator并且physical device两者都有问题。
提示:我将react-native-map-clustering包用于标记集群。
Mah*_*our 16
我尝试了两种可以稍微提高性能的方法
key以index(key={index})mapMarkers.map((marker, index) => {
return (<Marker
key={index}
...
/>)
});
Run Code Online (Sandbox Code Playgroud)
tracksViewChanges={false}或添加icon道具而不是imagemapMarkers.map((marker, index) => {
return (<Marker
key={index}
tracksViewChanges={false}
icon={require('./images/markers.png')}
...
/>)
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4403 次 |
| 最近记录: |