สอบถามเรื่องการหาระยะทางโดยการคำนวน จาก ละติจูด ลองจิจูดครับ แล้วนำมาแสดงใน google map ครับ
Google MAP CODE API
Date :
2011-06-04 13:30:18
By :
TEST_CODE
คือว่าเขาห้ามกำหนดเส้นทางใน google map ครับ ให้คำนวนจาก ค่าละติจูด ลองจิจูดมาลบกันแทน
แล้วสามารถ ปักหมุดพร้อมๆกันได้ไหมครับ
Date :
2011-06-04 13:48:47
By :
buraratn
จะทำขาย หรือทำแจก ถ้าแจกขอด้วยคน
หรือรับทำงานให้ลูกค้า แล้วจะแจกไม๊ แจกขอด้วยคน
Date :
2011-06-04 15:12:36
By :
Notice
ผมทำโปรเจคจบครับ
ติด F มาจะปีครึ่งระครับ(1ปีไปทหารครับ)
เอาไว้ทำเสร็จก่อนเถอะครับแล้วค่อยแจก สัญญาครับว่าถ้าสอบจบแล้วจะแจก
แต่ตอนนี้ผมว่าเริ่มทำเลยดีกว่าครับ ใครมีความรู้เรื่องนี้รบกวนด้วยนะครับ
Date :
2011-06-04 15:27:18
By :
buraratn
ใครรู้บ้างครับ ช่วยทีครับ
Date :
2011-06-05 14:41:23
By :
buraratn
งงครับ แต่ขอบคุณมากเลยครับ จะเอาไปศึกษาดูครับ
Date :
2011-06-05 16:43:58
By :
buraratn
รบกวนดูหน่อยครับว่าผมแปลง สูตรจาก จาวา เป้น 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
ช่วยดูหน่อยครับค่า $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
เงียบสนิจ
Date :
2011-06-19 16:42:31
By :
buraratn
ยังเงียบอยู่ครับ
Date :
2011-06-20 13:19:51
By :
buraratn
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>
ประวัติการแก้ไข 2011-06-20 15:04:28
Date :
2011-06-20 15:02:23
By :
buraratn
save รูป DB มาดูหน่อยคับ
Date :
2011-06-20 15:12:38
By :
TEST
Date :
2011-06-20 15:14:46
By :
buraratn
ลองดู
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
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
Load balance : Server 04