เนื้อหาส่วนที่ 3 จะเป็นแบบสั้นๆ เป็นวิธีการ ต่อเนื่องจาก ตอนที่ 1 และ ตอนที่ 2
แสดงตำแหน่งเพื่อนๆ จากฐานข้อมูล ใน google map ตอนที่ 1
https://www.ninenik.com/content.php?arti_id=479 via @ninenik
บันทึกตำแหน่งปัจจุบัน ใน google map ลงฐานข้อมูล ตอนที่ 2
https://www.ninenik.com/content.php?arti_id=480 via @ninenik
วัตถุประสงค์คือการสร้าง xml ไฟล์ ที่มีข้อมูลของผู้ใช้งาน สำหรับนำมาใช้
ในการแสดงตำแหน่ง บน google map
ในที่นี้ใช้ชื่อว่า firend_list.php เมื่อเรียกใช้งานจะได้เป็นไฟล์ xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?php header( "Content-type:text/xml; charset=UTF-8" ); header( "Cache-Control: no-store, no-cache, must-revalidate" ); header( "Cache-Control: post-check=0, pre-check=0" , false); mysql_connect( "localhost" , "root" , "" ) or die ( "Cannot connect the Server" ); mysql_select_db( "test" ) or die ( "Cannot select database" ); mysql_query( "set character set utf8" ); echo '<?xml version="1.0" encoding="utf-8"?>' ; ?> <markers> <?php $q = "SELECT * FROM user_position WHERE 1 ORDER BY user_position_id LIMIT 30 " ; $qr =mysql_query( $q ); while ( $rs =mysql_fetch_array( $qr )){ ?> <marker id= "<?=$rs['user_id']?>" > <name><?= $rs [ 'user_name' ]?></name> <latitude><?= $rs [ 'user_latitude' ]?></latitude> <longitude><?= $rs [ 'user_longitude' ]?></longitude> <lastdate><?= $rs [ 'user_datetime' ]?></lastdate> <icon><?= $rs [ 'user_icons' ]?></icon> </marker> <?php } ?> </markers> |
ผลลัพธ์ เมื่อมีการเรียกใช้งาน ก็จะได้
ข้อมูล โครงสร้างไฟล์ xml ดังนี้ (ข้อมูลทดสอบ ไฟล์ ตัวอย่าง คลิก )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <? xml version = "1.0" encoding = "utf-8" ?>< markers > < marker id = "1" > < name >Ninenik Narkdee</ name > < latitude >13.769639</ latitude > < longitude >100.61267210000001</ longitude > < lastdate >2014-03-09 18:40:26</ lastdate > < icon >//www.ninenik.com/demo/photo_avatar.php</ icon > </ marker > < marker id = "2" > < name >Guest001</ name > < latitude >13.769898251784323</ latitude > < longitude >100.63751220703125</ longitude > < lastdate >2014-03-09 18:31:13</ lastdate > < icon >//www.ninenik.com/demo/photo_avatar.php?user=2</ icon > </ marker > < marker id = "3" > < name >Guest002</ name > < latitude >13.756392915142058</ latitude > < longitude >100.6182861328125</ longitude > < lastdate >2014-03-09 18:32:48</ lastdate > < icon >//www.ninenik.com/demo/photo_avatar.php?user=3</ icon > </ marker > < marker id = "4" > < name >Guest003</ name > < latitude >13.758893962231816</ latitude > < longitude >100.56438446044922</ longitude > < lastdate >2014-03-09 18:34:11</ lastdate > < icon >//www.ninenik.com/demo/photo_avatar.php?user=4</ icon > </ marker > </ markers > |
เนื้อหาการสร้าง xml จากฐานข้อมูล เป็นเนื้อหาเก่า ประยุกต์จากบทความ
การดึงข้อมูล จากฐานข้อมูล สร้าง xml ไฟล์ ด้วย php
https://www.ninenik.com/content.php?arti_id=335 via @ninenik
สำหรับตอนต่อไป ตอนที่ 4 จะเป็นการ เรียกใช้ตำแหน่ง และข้อมูล
จาก xml ไฟล์มาใช้งาน ใน google map