4. - var map; เราสามารถลบแล้วมาประกาศตรง map = new เป็น var map = new ก็ได้
5. วิธีการสร้าง maeker
ตัวโค้ดทั้งหมด
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
function initMap() {
var map = new
google.maps.Map(document.getElementById('map'), {
6. center: {lat: 13.277383, lng: 100.925864},
zoom: 17
});
var marker1 = new google.maps.Marker({
position:{lat: 13.277383, lng: 100.925864},
map:map,
title:'Faculty of Geoinformatice'
});
var marker2 = new google.maps.Marker({
position:{lat: 13.296552, lng: 100.913317},
map:map,
title:'Seansuk tample'
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBq1eu0rPYkGrjqbGsmmZ00z-
_jYfhgl4Y&callback=initMap"
async defer></script>
</body>
</html>
คาสั่ง ของการเรียก Marker
Key ที่เราได้ทาการขอมาไว้ก่อนหน้านี้ถ้าไม่เปลี่ยนจะทาการเรียกแผนที่มาใช้งานไม่ได้
7. ตัวโค้ดหลักของเขียน marker
});
var marker1 = new google.maps.Marker({
position:{lat: 13.277383, lng: 100.925864},
map:map,
title:'Faculty of Geoinformatice'
});
แล้วดูผลรับ จะปรากฏหมุด(maeker)ขึ้นมา และมี Faculty of Geoinformatice ขึ้นมาเมื่อนาเม้าส์ไปชี้ เพราะ
ตรง title นั้นเราได้ใส่ตัวเเปลลงไปว่า title:'Faculty of Geoinformatice' ดังนั้งจึงปรากฏชื่อ Faculty of
Geoinformatice
8. เราสามารถเพิ่มหมุดได้โดยใช้คาสั่งคล้ายเดิม ต่อท้ายคาสั่งของ marker1
- โดยเปลี่ยน marker1 เป็น marker2 และ title:'Faculty of Geoinformatice' เป็น title:'Seansuk tample'
});
var marker2 = new google.maps.Marker({
position:{lat: 13.296552, lng: 100.913317},
map:map,
title:'Seansuk tample'
});
- SAVE
9. วิธีการเพิ่ม iconbase
ตัวรูป icon ที่เราจะเรียกมาใช้จะต้องถูกเก็บไว้ให้อยู่บนโลกออนไลน์ โดยเราจะหามาจากโลก
ออนไลน์เอง จากเว็บไซน์ที่มีการให้บริการตัว icon หรือจะเอาไปฝากไว้แล้วค่อยดึงมาใช้ก็ได้
ตัวโค้ดทั้งหมด
<!DOCTYPE html>
<html>
<head>
<title>Custom Markers</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map;
10. function initMap() {
map = new
google.maps.Map(document.getElementById('map'), {
zoom: 16,
center: {lat: 13.277605, lng: 100.926524},
mapTypeId: 'roadmap'
});
var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/';
var icons = {
parking: {
icon: iconBase + 'parking_lot_maps.png'
},
library: {
icon: iconBase + 'library_maps.png'
},
info: {
icon: iconBase + 'info-i_maps.png'
}
};
function addMarker(feature) {
var marker = new google.maps.Marker({
position: feature.position,
icon: icons[feature.type].icon,
map: map
});
}
var features = [
{