อยากได้การคำนวณ แบบว่าหา ระยะทางที่ใกล้ที่สุดครับ จาก lat ,logที่ผมปักครับ

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา อยากได้การคำนวณ แบบว่าหา ระยะทางที่ใกล้ที่สุดครับ จาก lat ,logที่ผมปักครับ

อยากได้การคำนวณ แบบว่าหา ระยะทางที่ใกล้ที่สุดครับ จาก lat ,logที่ผมปักครับ
<!doctype html>
<!--[if lt IE 7]> <html class="ie6 oldie"> <![endif]-->
<!--[if IE 7]>    <html class="ie7 oldie"> <![endif]-->
<!--[if IE 8]>    <html class="ie8 oldie"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="">
<!--<![endif]-->
<head>
 <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAt9V7-L8nBdCREaqDMDx0xBQuvtYmYw8_mCk5u1Mm1Kx-fDn-uBTwq5REXD_rGnieamLAw1CPXU_M4w" type="text/javascript" charset="utf-8"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Untitled Document</title>
<link href="../boilerplate.css" rel="stylesheet" type="text/css">
<link href="../find.php" rel="stylesheet" type="text/css">
<link href="../stylle.css" rel="stylesheet" type="text/css">
<!-- 
To learn more about the conditional comments around the html tags at the top of the file:
paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
 
Do the following if you're using your customized build of modernizr (http://www.modernizr.com/):
* insert the link to your js here
* remove the link below to the html5shiv
* add the "no-js" class to the html tags at the top
* you can also remove the link to respond.min.js if you included the MQ Polyfill in your modernizr build 
-->
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style type="text/css"> 
body { 
background-image: url(0) ; 
background-attachment:scoll; 
background-repeat:repeat; } 
</style>
<script src="../respond.min.js"></script>
</head>
<center><h1> Web App ค้นหาปั้มน้ำมัน :  Pump&nbsp; Search </h1></center>
</head>
<body>
<body bgcolor ='SpringGreen'>
<form name="form1" method="post" action="index2.php">
  <input type="submit" name="button" id="button" value="ย้อนหลัง">
</form>
<br/>
<div class="gridContainer clearfix">
  <div id="LayoutDiv1">
  <?
$conn=mysql_connect("localhost","root","root");
if(!empty($conn))
{
mysql_select_db("gisdb");
}else{
echo"�������ö�Դ��͡Ѻ�ҹ��������㹢�й��!";
  }
 
   mysql_db_query("gisdb","SET NAMES UTF8");
 
 $rs1 = mysql_query("select * from province");
 $row1 = mysql_fetch_array($rs1);   
 $prov_id = $row1["prov_id"];
 $prov_name = $row1["prov_name"];
 $prov_lat = $row1["prov_lat"];
 $prov_lon = $row1["prov_lon"];   
   echo $prov_lat;
   echo $prov_lon;
   echo $prov_name; 
 
 
?>
 
<center><div id="map" style="width:400px; height:400px"></div></center>
 
 
<script type="text/javascript">
 
//<![CDATA[
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
map.setCenter(new GLatLng(<? echo $prov_lat;?>,<? echo $prov_lon;?>), 9);
 
 
}
// Creates a marker whose info window displays the given number
function createMarker(point, number)
{
var marker = new GMarker(point);
// Show this markers index in the info window when it is clicked
var html = number;
GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
return marker;
};
</script>
 
 
 
 
<script>
GEvent.addListener(map,"click", function(overlay,latlng) {
if (overlay) {
return;
}
var tileCoordinate = new GPoint();
var tilePoint = new GPoint();
var currentProjection = G_NORMAL_MAP.getProjection();
tilePoint = currentProjection.fromLatLngToPixel(latlng, map.getZoom());
tileCoordinate.x = Math.floor(tilePoint.x / 256);
tileCoordinate.y = Math.floor(tilePoint.y / 256);
var myHtml = "Latitude: " + latlng.lat() + "<br/>Longitude: " + latlng.lng() + 
"<br/>The Tile Coordinate is:<br/> x: " + tileCoordinate.x + 
"<br/> y: " + tileCoordinate.y + "<br/> at zoom level " + map.getZoom(); 
map.openInfoWindow(latlng, myHtml);
});
</script>
<?
$rs1 = mysql_query("select * from pin where pin_name LIKE '%PTT%' ");
while($row1 = mysql_fetch_array($rs1))
$pin_name = $row1["pin_name"];
$building_lat = $row1["pin_lat"];
$building_lon = $row1["pin_lon"];
 
 
$pic = $row1["pic"];
$brand = $row1["brand"];
 
 
echo"<script>";
echo "var point = new GLatLng(" . $building_lat. "," . $building_lon. "); ";
echo "var marker = createMarker(point, '" .$pin_name."<img src=img/$pic>'); ";
echo "map.addOverlay(marker); ";
echo " ";
 
echo"</script>";
 
}
?>
<center>
 </p>
 
<form name="form1" method="post" action="findPETRONAS.php">
  <input type="submit" name="button10" id="button10" value="ปั้ม PETRONAS" />
</form>
<form name="form2" method="post" action="findBANGCHAK.php">
  <input type="submit" name="button3" id="button3" value="ปั้ม BANGCHAK" />
</form>
<form name="form3" method="post" action="findLPG.php">
  <input type="submit" name="button5" id="button5" value="ปั้ม LPG " />
</form>
<form name="form5" method="post" action="findCOSMO.php">
  <input type="submit" name="button7" id="button7" value="ปั้ม COSMO" />
</form>
<form name="form6" method="post" action="findCALTEX.php">
  <input type="submit" name="button4" id="button4" value="ปั้ม CALTEX" />
</form>
<form name="form7" method="post" action="findSUSCO.php">
  <input type="submit" name="button12" id="button12" value="ปั้ม SUSCO" />
</form>
<form name="form8" method="post" action="findESSO.php">
  <input type="submit" name="button6" id="button6" value="ปั้ม ESSO" />
</form>
<form name="form13" method="post" action="findNGV.php">
  <input type="submit" name="button2" id="button2" value="ปั้ม NGV" />
</form>
<form name="form4" method="post" action="findShell.php">
  <input type="submit" name="button11" id="button11" value="ปั้ม Shell" />
</form>
  <form name="form9" method="post" action="findPTT.php">
    <input type="submit" name="button" id="button" value="ปั้ม PTT" />
  </form>
  <form name="form10" method="post" action="findJET.php">
    <input type="submit" name="button8" id="button8" value="ปั้ม JET" />
  </form>
  <form name="form11" method="post" action="findTPI.php">
    <input type="submit" name="button13" id="button13" value="ปั้ม TPI" />
  </form>
  <form name="form12" method="post" action="findMP.php">
    <input type="submit" name="button9" id="button9" value="ปั้ม MP" />
  </form>
  <br/>  
  </center>
  <center><div id=footer data-role="footer" class="ui-bar-b">
    <h4><marquee width="270">
      
      design By : ทัตพงศ์ คำวงวาลย์
    </marquee></marquee>
  
</h4>
  </div>
</center>
  </div>
</div>
</body>
</html>
 


Lingaom2329@windowslive.com 171.100.152.xxx 02-10-2014 21:41:12

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
เหมือนเคยเจอ แต่ไม่เคยเอามาใช้ ลองดูตัวนี้เป็นแนวทาง

http://stackoverflow.com/questions/4057665/google-maps-api-v3-find-nearest-markers

อีกอันเป็นตัวที่ปรับใช้กับ google map v3

http://stackoverflow.com/questions/9156909/map-markers-is-undefined-google-map-api-v3

ดูจากสูตรการคำนวณแล้ว ปาดเหงื่อกันเลยทีเดียว  

ลิ้งค์เขาอ้างอิง จากตัวอย่างด้านบน

http://en.wikipedia.org/wiki/Haversine_formula

การหาตำแหน่งใกล้เคียง ในแผนที่ ถือว่าน่าสนใจ ไว้จะลองประยุกต์และทำเป็นบทความ ต่อไป



ninenik 1.47.81.xxx 03-10-2014
 ความคิดเห็นที่ 2
ขอบคุณ ครับ 


lingaom2329@windowslive.com 171.100.152.xxx 03-10-2014 19:52






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ