 |
|
ผมทำการดึงข้อมูลหมุดมาจาก mysql มาลงใน google map api ได้ครับ แต่พอดึงข้อมูลมามันบังคับไม่ได้ครับ ซูมเข้า-ออก เลื่อนแผนที่ในdiv ไม่ได้ครับ แต่แสดงผลตามปกติครับ โค๊ดนี้มีปัญหาตรงไหนหรือเปล่าครับ
Code (PHP)
<script>
function initMap() {
var mapOptions = {
center: {lat: 13.847860, lng: 100.604274},
zoom: 5,
}
var maps = new google.maps.Map(document.getElementById("map"),mapOptions);
var marker, info;
$.getJSON( "json.php", function( jsonObj ) {
//*** loop
$.each(jsonObj, function(i, item){
marker = new google.maps.Marker({
position: new google.maps.LatLng(item.dorm_lat, item.dorm_lon),
map: maps,
title: item.dorm_name
});
info = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
info.setContent(item.dorm_name);
info.open(maps, marker);
}
})(marker, i));
}); // loop
});
}
</script>
ผมเอาสคริปมาจากเว็บนี้ครับ
https://www.thaicreate.com/tutorial/google-maps-javascript-api-php-mysql-json.html
Tag : PHP, HTML, CSS, JavaScript, Ajax, XAMPP
|
ประวัติการแก้ไข 2020-10-15 20:54:52
|
 |
 |
 |
 |
Date :
2020-10-15 20:54:07 |
By :
siripong778 |
View :
689 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |