Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > สอบถามเรื่องการหาระยะทางโดยการคำนวน จาก ละติจูด ลองจิจูดครับ แล้วนำมาแสดงใน google map ครับ



 

สอบถามเรื่องการหาระยะทางโดยการคำนวน จาก ละติจูด ลองจิจูดครับ แล้วนำมาแสดงใน google map ครับ

 



Topic : 061178



โพสกระทู้ ( 345 )
บทความ ( 0 )



สถานะออฟไลน์




คือผมต้องการค้นหาหอพักที่อยุ่ห่างจากมหาลัย ไม่เกิน 5 กิโลเมตร คำนวนโดยใช้ค่าละติจูด ลองจิจูดครับ

เมื่อคำนวนเสร็จ สมมุติว่ามีจำนวน 5 หอพัก แลัวให้แสดงที่อยู่ทั้ง 5 หอพัก พร้อมกันในgoogle map ได้ไหมครับ



Tag : PHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-06-04 13:21:18 By : buraratn View : 7280 Reply : 16
 

 

No. 1



โพสกระทู้ ( 392 )
บทความ ( 0 )



สถานะออฟไลน์


Google MAP CODE API






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-04 13:30:18 By : TEST_CODE
 


 

No. 2



โพสกระทู้ ( 345 )
บทความ ( 0 )



สถานะออฟไลน์


คือว่าเขาห้ามกำหนดเส้นทางใน google map ครับ ให้คำนวนจาก ค่าละติจูด ลองจิจูดมาลบกันแทน

แล้วสามารถ ปักหมุดพร้อมๆกันได้ไหมครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-04 13:48:47 By : buraratn
 

 

No. 3

Guest


จะทำขาย หรือทำแจก ถ้าแจกขอด้วยคน
หรือรับทำงานให้ลูกค้า แล้วจะแจกไม๊ แจกขอด้วยคน
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-04 15:12:36 By : Notice
 


 

No. 4



โพสกระทู้ ( 345 )
บทความ ( 0 )



สถานะออฟไลน์


ผมทำโปรเจคจบครับ

ติด F มาจะปีครึ่งระครับ(1ปีไปทหารครับ)

เอาไว้ทำเสร็จก่อนเถอะครับแล้วค่อยแจก สัญญาครับว่าถ้าสอบจบแล้วจะแจก


แต่ตอนนี้ผมว่าเริ่มทำเลยดีกว่าครับ ใครมีความรู้เรื่องนี้รบกวนด้วยนะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-04 15:27:18 By : buraratn
 


 

No. 5



โพสกระทู้ ( 345 )
บทความ ( 0 )



สถานะออฟไลน์


ใครรู้บ้างครับ ช่วยทีครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-05 14:41:23 By : buraratn
 


 

No. 6

Guest


Code
SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( latitude ) ) * cos( radians( longtitude ) - radians(-122) ) + sin( radians(37) ) * sin( radians( latitude ) ) ) ) AS distance
FROM tabale HAVING distance <= 5 ORDER BY distance LIMIT 0 , 20;

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-05 16:38:58 By : deawx
 


 

No. 7



โพสกระทู้ ( 345 )
บทความ ( 0 )



สถานะออฟไลน์


งงครับ แต่ขอบคุณมากเลยครับ จะเอาไปศึกษาดูครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-05 16:43:58 By : buraratn
 


 

No. 8



โพสกระทู้ ( 345 )
บทความ ( 0 )



สถานะออฟไลน์


รบกวนดูหน่อยครับว่าผมแปลง สูตรจาก จาวา เป้น php ถูกไหมครับ

Code (PHP)
var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
      Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *
      Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
alrt("ระยะทางได้ผลลัพธ์ = " + d);


อันนี้  php  ครับ
<?
$R=6371;
dlat=(lat2-lat1);
dlon=(lon2-lon1);
$a=sin($dlat/2)*sin(dlat/2)+cos(lat1)*cos(lat2)*sin(dlon/2)*sin(dlon/2);
$c=2*atan2(sqrt $a,sqrt (1-$a));
$d=$R*$c;

?>



ประวัติการแก้ไข
2011-06-18 23:37:08
2011-06-18 23:50:52
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-18 23:36:43 By : buraratn
 


 

No. 9



โพสกระทู้ ( 345 )
บทความ ( 0 )



สถานะออฟไลน์


ช่วยดูหน่อยครับค่า $a กับ $c ไม่ออกครับ
Code (PHP)
$R=6371;
$dlat=(14.85467-$lat_prd);
$dlon=(103.48357-$lng_prd);
$a=sin($dlat/2)*sin(dlat/2)+cos($lat_prd)*cos(14.85467)*sin(dlon/2)*sin(dlon/2);
$c=2*atan2(sqrt($a),sqrt (1-$a));
$d=$R*$c;

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-19 00:23:07 By : buraratn
 


 

No. 10



โพสกระทู้ ( 345 )
บทความ ( 0 )



สถานะออฟไลน์


เงียบสนิจ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-19 16:42:31 By : buraratn
 


 

No. 11



โพสกระทู้ ( 345 )
บทความ ( 0 )



สถานะออฟไลน์


ยังเงียบอยู่ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-20 13:19:51 By : buraratn
 


 

No. 12



โพสกระทู้ ( 345 )
บทความ ( 0 )



สถานะออฟไลน์


Code (PHP)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=tis-620" />
<title>Google Map</title>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<style>
html {
height: auto;
}

body {
height: auto;
margin: 0;
padding: 0;
}
#map {
height: auto;
position: absolute;
bottom:0;
left:0;
right:0;
top:0;
}

@media print {
#map {
height: 950px;
}
}
</style>
</head>
<body>
<div id="map"></div>

<script type="text/javascript"> 
var locations = [ 
<?php
include"connect.php";

	$sql="select * from tb_product where id_prd='$id_prd' ";
	$result=mysql_db_query($db_Name,$sql);
while ($rs=mysql_fetch_array($result)) {
		$id_prd=$rs[id_prd];
		$code=sprintf("%05d",$id_prd);
		$lat_prd=$rs[lat_prd];
		$lng_prd=$rs[lng_prd];
      $name_prd=$rs[name_prd];}
while ($rs=mysql_fetch_array($result)) {
?>
['<?=$rs['name_prd']?>', <?=$rs['lat_prd']?>, <?=$rs['lng_prd']?>]
<? } ?>]; 
var map = new google.maps.Map(document.getElementById('map'), { 
zoom: 13, 
center: new google.maps.LatLng(14.85467, 103.48357), 
mapTypeId: google.maps.MapTypeId.ROADMAP 
}); 
var infowindow = new google.maps.InfoWindow(); 
var marker, i; for (i = 0; i < locations.length; i++) { 
marker = new google.maps.Marker({ 
position: new google.maps.LatLng(locations[i][1], locations[i][2]), 
map: map 
}); 

google.maps.event.addListener(marker, 'click', (function(marker, i) { 
return function() { 
infowindow.setContent(locations[i][0]); 
infowindow.open(map, marker); 
} 
})
(marker, i)); 
} 
</script>
</body>
</html>


r


ประวัติการแก้ไข
2011-06-20 15:04:28
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-20 15:02:23 By : buraratn
 


 

No. 13



โพสกระทู้ ( 392 )
บทความ ( 0 )



สถานะออฟไลน์


save รูป DB มาดูหน่อยคับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-20 15:12:38 By : TEST
 


 

No. 14



โพสกระทู้ ( 345 )
บทความ ( 0 )



สถานะออฟไลน์


c
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-20 15:14:46 By : buraratn
 


 

No. 15



โพสกระทู้ ( 392 )
บทความ ( 0 )



สถานะออฟไลน์


ลองดู

Code (PHP)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=tis-620" />
<title>Google Map</title>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<style>
html {
height: auto;
}

body {
height: auto;
margin: 0;
padding: 0;
}
#map {
height: auto;
position: absolute;
bottom:0;
left:0;
right:0;
top:0;
}

@media print {
#map {
height: 950px;
}
}
</style>
</head>
<body>
<div id="map"></div>

<script type="text/javascript"> 
<?php
@include"connect.php";
$id_prd = 105;

	$sql="select * from tb_product where id_prd='$id_prd' ";
	$result=mysql_db_query($db_Name,$sql);
	$rs=mysql_fetch_array($result);
?>


var locations = ['<?=$rs['name_prd']?>', <?=$rs['lat_prd']?>, <?=$rs['lng_prd']?>];
var map = new google.maps.Map(document.getElementById('map'), { 
zoom: 13, 
center: new google.maps.LatLng(14.85467, 103.48357), 
mapTypeId: google.maps.MapTypeId.ROADMAP 
}); 
var infowindow = new google.maps.InfoWindow(); 
var marker, i; for (i = 0; i < locations.length; i++) { 
marker = new google.maps.Marker({ 
position: new google.maps.LatLng(locations[i][1], locations[i][2]), 
map: map 
}); 

google.maps.event.addListener(marker, 'click', (function(marker, i) { 
return function() { 
infowindow.setContent(locations[i][0]); 
infowindow.open(map, marker); 
} 
})
(marker, i)); 
} 
</script>
</body>
</html>



ประวัติการแก้ไข
2011-06-20 15:36:15
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-20 15:34:41 By : TEST
 


 

No. 16



โพสกระทู้ ( 345 )
บทความ ( 0 )



สถานะออฟไลน์


phpsqlsearch_genxml.php

Code (PHP)
<?php  
require("phpsqlsearch_dbinfo.php");

// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);

// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
  die("Not connected : " . mysql_error());
}

// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ("Can\'t use db : " . mysql_error());
}

// Search the rows in the markers table
$query = sprintf("SELECT id_prd,name_prd,lat_prd,lng_prd, ( 6371 * acos( cos( radians(14.85467) ) * cos( radians( lat_prd ) ) * cos( radians( lng_prd ) - radians(103.48357) ) + sin( radians(14.85467) ) * sin( radians( lat_prd ) ) ) ) AS distance FROM tb_product HAVING distance ORDER BY distance LIMIT 0 , 20",
  mysql_real_escape_string($center_lat),
  mysql_real_escape_string($center_lng),
  mysql_real_escape_string($center_lat),
  mysql_real_escape_string($radius));
$result = mysql_query($query);

$result = mysql_query($query);
if (!$result) {
  die("Invalid query: " . mysql_error());
}

header("Content-type: text/xml");

// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  $node = $dom->createElement("marker");
  $newnode = $parnode->appendChild($node);
  $newnode->setAttribute("name_prd", $row['name_prd']);
  $newnode->setAttribute("address_prd", $row['address_prd']);
  $newnode->setAttribute("lat_prd", $row['lat_prd']);
  $newnode->setAttribute("lng_prd", $row['lng_prd']);
  $newnode->setAttribute("distance", $row['distance']);
}

echo $dom->saveXML();
?>


Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="content-type" content="text/html; charset=tis-620"/>
<title>Google Maps AJAX + MySQL/PHP Example</title>
    <script src="http://maps.google.com/maps?file=api&v=2&key=abcdef"
            type="text/javascript"></script>

    <script type="text/javascript">
    //<![CDATA[
    var map;
    var geocoder;

    function load() {
      if (GBrowserIsCompatible()) {
        geocoder = new GClientGeocoder();
        map = new GMap2(document.getElementById('map'));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(14.85467, 103.48357),13);
      }
    }

   function searchLocations() {
     var address = document.getElementById('addressInput').value;
     geocoder.getLatLng(address, function(latlng) {
       if (!latlng) {
         alert(address + ' not found');
       } else {
         searchLocationsNear(latlng);
       }
     });
   }

   function searchLocationsNear(center) {
     var radius = document.getElementById('radiusSelect').value;
     var searchUrl = 'phpsqlsearch_genxml.php?lat_prd=' + center.lat() + '&lng_prd=' + center.lng() + '&radius=' + radius;
     GDownloadUrl(searchUrl, function(data) {
       var xml = GXml.parse(data);
       var markers = xml.documentElement.getElementsByTagName('marker');
       map.clearOverlays();

       var sidebar = document.getElementById('sidebar');
       sidebar.innerHTML = '';
       if (markers.length == 0) {
         sidebar.innerHTML = 'No results found.';
         map.setCenter(new GLatLng(14.85467, 103.48357),13);
         return;
       }

       var bounds = new GLatLngBounds();
       for (var i = 0; i < markers.length; i++) {
         var name = markers[i].getAttribute('name_prd');
         var address = markers[i].getAttribute('address_prd');
         var distance = parseFloat(markers[i].getAttribute('distance'));
         var point = new GLatLng(parseFloat(markers[i].getAttribute('lat_prd')),
                                 parseFloat(markers[i].getAttribute('lng_prd')));
         
         var marker = createMarker(point, name, address);
         map.addOverlay(marker);
         var sidebarEntry = createSidebarEntry(marker, name, address, distance);
         sidebar.appendChild(sidebarEntry);
         bounds.extend(point);
       }
       map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
     });
   }

    function createMarker(point, name, address) {
      var marker = new GMarker(point);
      var html = '<b>' + name + '</b> <br/>' + address;
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }

    function createSidebarEntry(marker, name, address, distance) {
      var div = document.createElement('div');
      var html = '<b>' + name + '</b> (' + distance.toFixed(1) + ')<br/>' + address;
      div.innerHTML = html;
      div.style.cursor = 'pointer';
      div.style.marginBottom = '5px'; 
      GEvent.addDomListener(div, 'click', function() {
        GEvent.trigger(marker, 'click');
      });
      GEvent.addDomListener(div, 'mouseover', function() {
        div.style.backgroundColor = '#eee';
      });
      GEvent.addDomListener(div, 'mouseout', function() {
        div.style.backgroundColor = '#fff';
      });
      return div;
    }
    //]]>

  </script>
</head>

<body onload="load()" onunload="GUnload()">
  Radius: 
    <select id="radiusSelect">

      <option value="25" selected>25</option>
      <option value="100">100</option>

      <option value="200">200</option>

    </select>

    <input type="button" onclick="searchLocations()" value="Search Locations"/>
    <br/>    
    <br/>
<div style="width:600px; font-family:Arial, 
sans-serif; font-size:11px; border:1px solid black">
  <table> 
    <tbody> 
      <tr id="cm_mapTR">

        <td width="200" valign="top"> <div id="sidebar" style="overflow: auto; height: 400px; font-size: 11px; color: #000"></div>

        </td>
        <td> <div id="map" style="overflow: hidden; width:400px; height:400px"></div> </td>

      </tr> 
    </tbody>
  </table>
</div>    
</body>
</html>

Code (PHP)
<?
$username="root";
$password="1234";
$database="db_shop";
?>


ไฟล์ xml ใช้แบบดึงออกจากฐานข้อมูลไม่รุ้ว่าเขียนอย่างนี้หรือเปล่าครับ
Code (PHP)
<?php
header("Content-type:text/xml; charset=tis-620");              
header("Cache-Control: no-store, no-cache, must-revalidate");             
header("Cache-Control: post-check=0, pre-check=0", false);   
mysql_connect("localhost","root","1234") or die("Cannot connect the Server");
mysql_select_db("db_shop") or die("Cannot select database");
mysql_query("set character set tis620");
echo '<?xml version="1.0" encoding="tis-620"?>';
?>
<markers>
<?
$q = " SELECT * FROM tb_product  ";       
$q .= " LEFT JOIN tb_type ON tb_product .ref_id_type = tb_type.id_type";
$q .=	" LEFT JOIN tb_type_lease ON tb_product .ref_id_type_lease = tb_type_lease.id_type_lease";
$q .=	" $where"; 
$qr=mysql_query($q);
while($rs=mysql_fetch_array($qr)){
?>
	<marker id="<?=$rs['id_prd']?>">
        <name><?=$rs['name_prd']?></name>
		<name_type><?=$rs['name_type']?></name_type>
        <name_type_lease><?=$rs['name_type_lease']?></name_type_lease>
		 <detail_prd><?=$rs['detail_prd']?></detail_prd>
        <price_prd><?=$rs['price_prd']?></price_prd>
		 <address_prd><?=$rs['address_prd']?></address_prd>
        <tel_prd><?=$rs['tel_prd']?></tel_prd>
        <lat_prd><?=$rs['lat_prd']?></lat_prd>
		<lng_prd><?=$rs['lng_prd']?></lng_prd>
    </marker>
<?php } ?>
</markers>




แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-25 16:05:33 By : buraratn
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถามเรื่องการหาระยะทางโดยการคำนวน จาก ละติจูด ลองจิจูดครับ แล้วนำมาแสดงใน google map ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่