React map
React 與 Google MAP
componentDidMount() {
const googleMapURL: `https://maps.googleapis.com/maps/api/js?key=${API_KEY}`,
if (!window.google) {
const scriptjs = require(`scriptjs`);
scriptjs(googleMapURL, () => this.initMap());
} else {
this.initMap();
}
}
initMap() {
const google = window.google;
const map = new google.maps.Map(
document.getElementById(填入在DOM上的一個空的 div ID), // 初始化地圖
{
zoom: 15,
center: { lat: 1.2948257152432294, lng: 103.85845150268554 },
fullscreenControl: false, // 隱藏預設的地圖按鈕
streetViewControl: false, // 隱藏預設的地圖按鈕
mapTypeControlOptions: {
mapTypeIds: [],
},
},
);
window.map = map;
}客製化地圖
Last updated