 |
[PHP]
รบกวนถามเรื่อง Google map ด้วยค่ะ ดึงหมุดจากฐานข้อมูลแล้วไม่ขึ้น |
|
 |
|
|
 |
 |
|
https://www.thaicreate.com/php/forum/061774.html
จากที่ลองศึกษาจากหัวข้อนี้ค่ะ ลองนำมาใช้ดู แต่ฐานข้อมูลเราเป็น Mssql อ่ะค่ะ พอดึงหมุดจากฐานข้อมูลแล้ว มันไม่แสดงน่ะคะ ขึ้นมาแต่แผนที่อย่างเดียว รบกวนช่วยดูให้หน่อย ว่าเราทำผิดตรงไหนหรือเปล่า
Code (PHP)
01. <!DOCTYPE html>
02. <html>
03. <head>
04. <meta http-equiv= "content-type" content= "text/html; charset=UTF-8" />
05. <title>Google Map Test by Deawx</title>
07. <style>
08. html {
09. height: auto;
10. }
11.
12. body {
13. height: auto;
14. margin: 0;
15. padding: 0;
16. }
17. #map {
18. height: auto;
19. position: absolute;
20. bottom:0;
21. left:0;
22. right:0;
23. top:0;
24. }
25.
26. @media print {
27. #map {
28. height: 950px;
29. }
30. }
31. </style>
32. </head>
33. <body>
34. <div id= "map" ></div>
35.
36. <script type= "text/javascript" >
37. var locations = [
38. <?php
39. include ( "dbcon.php" );
40. $strSQL = "SELECT * FROM LocationTravel " ;
41. $objQuery = mssql_query( $strSQL ) or die ( "Error Query [" . $strSQL . "]" );
42. $objResult = mssql_fetch_array( $objQuery );
43. ?>
44. [ '<?=$objResult["Name_locat"];?>' ,<?= $objResult [ "lat" ];?>, <?= $objResult [ "lng" ];?>]
45. ];
46. var map = new google.maps.Map(document.getElementById( 'map' ), {
47. zoom: 13,
48. center: new google.maps.LatLng(14.972149187588654,102.07225799560547),
49. mapTypeId: google.maps.MapTypeId.ROADMAP
50. });
51. var infowindow = new google.maps.InfoWindow();
52. var marker, i; for (i = 0; i < locations.length; i++) {
53. marker = new google.maps.Marker({
54. position: new google.maps.LatLng(locations[i][1], locations[i][2]),
55. title : locations[i][0],
57. map: map
58. });
59.
60. google.maps.event.addListener(marker, 'click' , ( function (marker, i) {
61. return function () {
62. infowindow.setContent(locations[i][0]);
63. infowindow.open(map, marker);
64. }
65. })
66. (marker, i));
67. }
68. </script>
69. </body>
70. </html>
Tag : PHP, Ms SQL Server 2008
|
|
 |
 |
 |
 |
Date :
2012-02-23 12:14:14 |
By :
erlare |
View :
1311 |
Reply :
13 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผิดที่ ถ้ามีหมุดหลายหมุด เราต้องคั่นด้วยลูกน้ำ (,) ในแต่ละหมุดครับ
หากมีหมุดเดียว มันจะขึ้นให้ ถ้าแบบนั้น
|
 |
 |
 |
 |
Date :
2012-02-23 16:51:46 |
By :
deawx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คั่นตรงไหนอ่า...
|
 |
 |
 |
 |
Date :
2012-02-23 22:14:30 |
By :
kaiba |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แต่เราก้อลองกำหนดให้ id ขึ้นมาตค่าเดียวแล้วนะ มันก้อยังไม่แสดงอ่า
|
 |
 |
 |
 |
Date :
2012-02-23 22:23:06 |
By :
erlare |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
https://www.thaicreate.com/community/google-map-earth-multiple-marker.html อัปเดตให้ใช้ google earth ด้วย
https://www.thaicreate.com/community/google-map-multiplemarker.html จะอ้างอิงจากลิงค์นี้เป็นหลักนะครับ
Code (PHP)
01. <!DOCTYPE html>
02. <html>
03. <head>
04. <meta http-equiv= "content-type" content= "text/html; charset=UTF-8" />
05. <title>Google Map Test by Deawx</title>
07. <style>
08. html {
09. height: auto;
10. }
11.
12. body {
13. height: auto;
14. margin: 0;
15. padding: 0;
16. }
17. #map {
18. height: auto;
19. position: absolute;
20. bottom:0;
21. left:0;
22. right:0;
23. top:0;
24. }
25.
26. @media print {
27. #map {
28. height: 950px;
29. }
30. }
31. </style>
32. </head>
33. <body>
34. <div id= "map" ></div>
35.
36. <script type= "text/javascript" >
37. var locations = [
38. <?php
39. include ( "dbcon.php" );
40. $strSQL = "SELECT * FROM LocationTravel " ;
41. $objQuery = mssql_query( $strSQL ) or die ( "Error Query [" . $strSQL . "]" );
42. $objResult = mssql_fetch_array( $objQuery );
43. ?>
44. [ '<?=$objResult["Name_locat"];?>' , <?= $objResult [ "lat" ];?>, <?= $objResult [ "lng" ];?>, 1],
45. ];
46. var map = new google.maps.Map(document.getElementById( 'map' ), {
47. zoom: 13,
48. center: new google.maps.LatLng(15.105355046221582, 104.31570053100586),
49. mapTypeId: google.maps.MapTypeId.ROADMAP
50. });
51. var infowindow = new google.maps.InfoWindow();
52. var marker, i; for (i = 0; i < locations.length; i++) {
53. marker = new google.maps.Marker({
54. position: new google.maps.LatLng(locations[i][1], locations[i][2]),
55. map: map
56. });
57.
58. google.maps.event.addListener(marker, 'click' , ( function (marker, i) {
59. return function () {
60. infowindow.setContent(locations[i][0]);
61. infowindow.open(map, marker);
62. }
63. })
64. (marker, i));
65. }
66. </script>
67. </body>
68. </html>
ให้ลองสักเกตุโค้ดต้นฉบับ กับของเราดูนะครับ ว่ามันตกตรงใหน ที่ตัวแปรไม่ครบ ตัวกำหนด Element array ตัวใหนไม่ครบอะจ้า
|
 |
 |
 |
 |
Date :
2012-02-23 23:56:04 |
By :
deawx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อลงเอาโค๊ดที่คุณพี่ให้มาไปทำดูแล้ว แต่ก็ยังไม่ขึ้นอยู่ดีอ่ะคะ
|
 |
 |
 |
 |
Date :
2012-02-24 00:15:53 |
By :
erlare |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
บรรทัดที่ 44 ['<?=$objResult["Name_locat"];?>', <?=$objResult["lat"];?>, <?=$objResult["lng"];?>, 1]
ตัด , ออกครับ เกินไป ตัวหนึ่ง
|
ประวัติการแก้ไข 2012-02-24 01:44:54
 |
 |
 |
 |
Date :
2012-02-24 01:43:28 |
By :
deawx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณพี่หมายถึงหลังสุดป่าวคะที่ให้ตัด ตัดแล้ว มันก็ไม่ขึ้นเหมือนเดิมอ่ะคะ
เลยลองทำแบบนี้ดู
['<?=$objResult["Name_locat"];?>', <?=$objResult["lat"];?>,<?=$objResult["lng"];?>,1],
['<?=$objResult["Name_locat"];?>', <?=$objResult["lat"];?>,<?=$objResult["lng"];?>,2],
ปรากฏว่ามันออกหมุดเดียว คือค่าแรกในฐานข้อมูล
เหมือนว่ามันไม่ดึงบรรทัดแรกมาค่ะ ดึงบรรทัดที่สองมา แต่ลบออกให้เหลือบรรทัดเดียวก้อจะไม่ออกเหมือนเดิม
|
 |
 |
 |
 |
Date :
2012-02-24 02:06:10 |
By :
erlare |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดูตามลิงค์ตัวอย่าง แล้วนำไปประยุกต์ได้เลยจ๊ะ
|
 |
 |
 |
 |
Date :
2012-02-24 10:51:39 |
By :
deawx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะ แต่ก็ยังไม่ได้อยุ่ดี อิอิ
|
 |
 |
 |
 |
Date :
2012-02-24 20:38:45 |
By :
erlare |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้ลองใส่ while ให้วน
$objResult = mssql_fetch_array($objQuery);
ปรากฏว่า หมุดที่ออกเป็น ข้อมูลสุดท้ายในตารางเรา
แลวก็ออกมาอันเดียว หุหุ
สู้ต่อไป
|
 |
 |
 |
 |
Date :
2012-02-24 23:10:52 |
By :
erlare |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เริ่มเดินเป็นก้าวแรกได้แล้ว ... เด่วอีกหน่อยก็ไปก้าวสอง หละจ้า .. สู้ ๆ
|
 |
 |
 |
 |
Date :
2012-02-25 00:00:49 |
By :
deawx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำไมมันถึงออกมาแค่ค่าสุดท้ายอ่ะคะ
พอเอา while ออก มันก้ออกแค่ค่าแรกค่าเดียวอีก
|
 |
 |
 |
 |
Date :
2012-02-25 03:21:13 |
By :
erlare |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วนะคะ กว่าจาได้ เกือบตาย ต้องใส่ , ด้วยอ่ค่ะ ถึงจาออก
Code (PHP)
01. <?
02. session_start();
03. ?>
04. <!DOCTYPE html>
05. <html>
06. <head>
07. <meta http-equiv= "Content-Type" content= "text/html; charset=windows-874" />
08. <title>Google Map Test by Deawx</title>
10. <style>
11. html {
12. height: auto;
13. }
14.
15. body {
16. height: auto;
17. margin: 0;
18. padding: 0;
19. }
20. #map {
21. width:800px;
22. height:600px;
23. margin:auto;
24. }
25.
26.
27. }
28. </style>
29. </head>
30. <script type= "text/javascript" >
31.
32. function init() {
33. var map = new google.maps.Map(document.getElementById( 'map' ), {
34. zoom: 13,
35. center: new google.maps.LatLng(14.972149187588654,102.07225799560547),
36. mapTypeId: google.maps.MapTypeId.ROADMAP
37. });
38. <?php
39. include ( "dbcon.php" );
40. $strSQL = "SELECT * FROM LocationTravel " ;
41. $objQuery = mssql_query( $strSQL ) or die ( "Error Query [" . $strSQL . "]" );
42. ?>
43. var locations = [
44. <? while ( $objResult = mssql_fetch_array( $objQuery )){?>
45. [ '<?=$objResult[' Name_locat '];?>' ,<?= $objResult [ 'lat' ];?>,<?= $objResult [ 'lng' ]; ?>,1] , <? }?>
46. ];
47. var infowindow = new google.maps.InfoWindow();
48.
49. var marker, i; for (i = 0; i < locations.length; i++) {
50. marker = new google.maps.Marker({
51. position: new google.maps.LatLng(locations[i][1], locations[i][2]),
52. draggable : false,
53. title : locations[i][0],
55. map:map
56. });
57.
58. google.maps.event.addListener(marker, 'click' , ( function (marker, i) {
59. return function () {
60. infowindow.setContent(locations[i][0]);
61. infowindow.open(map, marker);
62. }
63. })
64. (marker, i));
65. }
66. }
67. google.maps.event.addDomListener(window, 'load' , init);
68. </script>
69. <body>
70. <div id= "map" ></div>
71. </body>
72. </html>
|
 |
 |
 |
 |
Date :
2012-02-25 03:39:20 |
By :
erlare |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|