*สอบถามค่ะ* ถ้าต้องการให้ pointA รับค่าละติจูดลองจิจูดแบบอัตโนมัติมีวิธีไหนทำได้บ้างคะ
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา *สอบถามค่ะ* ถ้าต้องการให้ pointA รับค่าละติจูดลองจิจูดแบบอัตโนมัติมีวิธีไหนทำได้บ้างคะ
*สอบถามค่ะ* ถ้าต้องการให้ pointA รับค่าละติจูดลองจิจูดแบบอัตโนมัติมีวิธีไหนทำได้บ้างคะ
Copy
ตามหัวข้อเลยค่ะ คือเราต้องการให้ pointA ในโค้ดบรรทัดที่ 2 เป็นการรับเลยละติจูดลองจิจูดแบบอัตโนมัติ พอมีวิธีไหนแก้ได้บ้างคะ
ส่วนนี่เป็นรูปภาพที่แสดงขึ้นหน้าเว็บค่ะ
![]()
ส่วนอันนี้เป็นโค้ด HTML ค่ะ
function initMap() {
var pointA = new google.maps.LatLng(12.602035, 102.096195);
var pointB = new google.maps.LatLng(12.663197, 102.105074);
var myOptions = {
zoom: 7,
center: pointA
};
var map = new google.maps.Map(document.getElementById('map-canvas'), myOptions),
// Instantiate a directions service.
directionsService = new google.maps.DirectionsService,
directionsDisplay = new google.maps.DirectionsRenderer({
map: map
});
var markerA = new google.maps.Marker({
position: pointA,
title: "point A",
label: "A",
map: map
});
var markerB = new google.maps.Marker({
position: pointB,
title: "point B",
label: "39",
map: map
});
// get route from A to B
calculateAndDisplayRoute(directionsService, directionsDisplay, pointA, pointB);
}
function calculateAndDisplayRoute(directionsService, directionsDisplay, pointA, pointB) {
directionsService.route({
origin: pointA,
destination: pointB,
travelMode: google.maps.TravelMode.DRIVING
}, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
ส่วนนี่เป็นรูปภาพที่แสดงขึ้นหน้าเว็บค่ะ
ส่วนอันนี้เป็นโค้ด HTML ค่ะ
<!DOCTYPE html>
<html>
<head>
<title>Add Map</title>
<link rel="stylesheet" type="text/css" href="./สไตล์แบบลองๆ.css" />
<script src="./direction.js"></script>
</head>
<body>
<h3>My Google Maps Demo</h3>
<!--The div element for the map -->
<div id="map-canvas"></div>
<!-- Async script executes immediately and must be after any DOM elements used in callback. -->
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAn9F7bRABwPnrEO3YjQq6jHHWLEyqB7xU&callback=initMap&libraries=&v=weekly"
async defer></script>
</body>
</html>
คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา
โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ