Mapbox 를 이용하여 campground 상세 페이지에서 위치가 지도에 표시되도록 했다.
👇코드 보러가기
https://github.com/Sara-Jo/BeWild/tree/e4c0bb619ab3cd70f1db36107ee9c456e70be4a2
campground
스키마에 위치정보인 geometry
를 추가하고, seed campground
들에는 디폴트 위치값이 저장되도록 했다.[models/campground.js]
const CampgroundSchema = new Schema ({
title: String,
images: [ImageSchema],
geometry: {
type: {
type: String,
enum: ['Point'],
required: true
},
coordinates: {
type: [Number],
required: true
}
},
price: Number,
description: String,
location: String,
...
[seeds/index.js]
...
geometry: {
type: "Point",
coordinates: [-113.1331, 47.0202]
},
...
campground
생성시에 location
정보를 지도에 표시할 수 있도록 geoData
로 프로세싱한 후 스키마에 저장해주었다.[controllers/campgrounds.js]