2017-12-13 1 views
-4

나는 이런 모양의 Markers google maps 배열을 가지고 있습니다.자바 스크립트로 빌드하기

markers: [{ 
    position: { 
     lat: 37.0636782, 
     lng: -8.0288746 
    }, 
    infoText: 'Marker 1' 
}], 

나는 또한 내 CMS에서 가져온 콘텐츠가 있습니다.

[{ 
    "latitude": "37.0636782", 
    "longitude": "-8.0288746", 
    "info_snippet": "test123" 
}, 
{ 
    "latitude": "37.0636789", 
    "longitude": "-8.0288745", 
    "info_snippet": "test111" 
}] 

두 번째 배열을 가져 와서 첫 번째 배열과 동일하게 출력하고 싶습니다. 이것이 가능한가?

요청한 루프는 내가 만든 루프입니다.

+0

죄송합니다 : 귀하의 경우는 이런 일이 될 것입니다. downvote 필요가 없습니다. 여기 내 시도 배열에 게시됩니다. –

+0

'Array.prototype.map'을 한 번 호출하면이 값이 동적이되도록 "좌표"를 반복하고 싶습니다. – Vivick

답변

1

원본을 통해지도를 만들고 사용자 정의 키를 만듭니다.

this.pins = response.data.acf.map_markers; 

this.pins.map(({latitude, longitude, info_snippet}) => ({ 
    position: { lat: latitude, lng: longitude }, 
    infoText: info_snippet 
})); 

const coords = [{ 
 
    "latitude": "37.0636782", 
 
    "longitude": "-8.0288746", 
 
    "info_snippet": "test123" 
 
    }, 
 
    { 
 
    "latitude": "37.0636789", 
 
    "longitude": "-8.0288745", 
 
    "info_snippet": "test111" 
 
    } 
 
]; 
 

 
const newCoords = coords.map(({latitude, longitude, info_snippet}) => ({ 
 
    position: { lat: latitude, lng: longitude }, 
 
    infoText: info_snippet 
 
})); 
 

 
console.log(newCoords);

+0

그게 얼마나 어려울까요? –

+0

나는 혼란스러워. 'map()'을 사용하면 본질적으로'coords'를 반복합니다. –

관련 문제