各位好,小弟第一次來這個版上發問,有甚麼規矩沒注意到的,
還請多多包涵,小弟剛接觸js,還不太懂該怎麼做,
小弟我有個CSV資料,裡面有很多的欄位,但是我想要將裡面的
經緯度標註到google map 上,而在marker上,我要顯示資料裡的地點,
對此,小弟找官方的範例來做修改,
官方範例:
https://developers.google.com/maps/documentation/javascript/examples/map-projection-simple?hl=zh-tw
但是官方範例卻是將座標寫死在js裡,我想改成可以從CSV檔裡取得經緯座標,
然後標在地圖上,我不知道該怎麼做,還請各位強者指點一下。
以下附上我修改的code及CSV:(githut目前把我的帳號當作是機器人,還請見諒)
CSV檔:https://drive.google.com/open?id=0B6SUWnrBmDwScUpNaTFaM1ZnODg&authuser=0
<script
src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
<script>
var Hsinchu = new google.maps.LatLng(24.774906,120.970782);
var Taoyuan = new google.maps.LatLng(24.810556,121.244167);
var Taichung = new google.maps.LatLng(24.205938,121.010132);
var equator = new google.maps.LatLng(23.9764042,120.9821779);/*定位點*/
var Taipie = new google.maps.LatLng(25.15364,121.547862);
var Nantou = new google.maps.LatLng(23.8654727,120.9120994);
var Kaohsiung = new google.maps.LatLng(23.114592,120.6314948);
var Tainan = new google.maps.LatLng(23.21103,120.348636);
var locationArray = [Hsinchu,Taoyuan,Taichung,Taipie,Nantou,Kaohsiung,Tainan];
var locationNameArray =
['Hsinchu','Taoyuan','Taichung','Taipie','Nantou','Kaohsiung','Tainan'];
function initialize() {
var TaiwanMap;
var mapOptions = {
zoom: 8,
center:equator,
};
TaiwanMap = new
google.maps.Map(document.getElementById('map-canvas'),mapOptions);
var coord;
for (coord in locationArray) {
var marker = new google.maps.Marker({
position: locationArray[coord],
map: TaiwanMap,
title: locationNameArray[coord]
});
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>