該
您必須更改渲染wildfires串列,如下所示,
{
props.wildfires.map((w:any, i:any)=><Marker
key={w.id}
lat={w.geometry[0].coordinates[1]}
lng={w.geometry[0].coordinates[0]}
name={w.title}
color="red" />
)}
我創建了演示專案而不是從 加載資料NASA's REST API,我模擬了來自NASA'sapi 回應的幾個資料。
演示
uj5u.com熱心網友回復:
將屬性添加到 GoogleMapReact 標簽:
onGoogleApiLoaded={({map, maps}) => renderMarkers(map, maps)}
創建函式 renderMarkers:
const renderMarkers = (map, maps) => {
for(item of props.wildfires){
let marker = new maps.Marker({
position: {lat: item.geometry[0].coordinates[0], lng: item.geometry[0].coordinates[1]},
map,
title: 'My Marker'
});
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/313502.html
