Last active
June 5, 2019 09:54
-
-
Save letswritetw/256523748cead02eb27fc266d3906a25 to your computer and use it in GitHub Desktop.
google-map-api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const googleMap = new Vue({ | |
el: '#app', | |
data: { | |
map: null | |
}, | |
methods: { | |
// init google map | |
initMap() { | |
// 預設顯示的地點:台北市政府親子劇場 | |
let location = { | |
lat: 25.0374865, // 經度 | |
lng: 121.5647688 // 緯度 | |
}; | |
// 建立地圖 | |
this.map = new google.maps.Map(document.getElementById('map'), { | |
center: location, | |
zoom: 16, | |
mapTypeId: 'terrain' | |
}); | |
// 放置多個marker | |
fetch('./map.geojson') | |
.then(results => results.json()) | |
.then(result => { | |
let res = result.features; | |
Array.prototype.forEach.call(res, r => { | |
let latLng = new google.maps.LatLng(r.geometry.coordinates[0], r.geometry.coordinates[1]); | |
let marker = new google.maps.Marker({ | |
position: latLng, | |
map: this.map | |
}); | |
}); | |
}); | |
} | |
}, | |
created() { | |
window.addEventListener('load', () => { | |
this.initMap(); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment