【发布时间】:2011-08-05 03:48:17
【问题描述】:
我目前正在从事一个项目,但遇到了很大的障碍。 我正在使用谷歌地图 API 运行地图应用程序,我需要计算两点之间的中点,即 4 个总点(纬度/经度),这些点存储为用户的 php 值。
我目前使用的公式需要将我的以度为单位的值转换为弧度。 然后我需要将它们转换回度数以插入我代码的谷歌映射部分。
我需要计算这个点,这样我就可以将它显示为我的地图中间,这样它就会整齐地居中显示。
这是我当前的代码:
<?php
ob_start();
?>
<?php
$from = $_POST["from"];
$to = $_POST["to"];
$connection = mysql_connect("localhost", "dlazett", "PASSWORD");
mysql_select_db("dlazett", $connection);
$f = mysql_query ("SELECT * FROM capstone WHERE id = '$from' ",
$connection);
$wfrom = mysql_fetch_array($f);
$latf = $wfrom["lat"];
$lonf = $wfrom["lon"];
$t = mysql_query ("SELECT * FROM capstone WHERE id = '$to' ",
$connection);
$wto = mysql_fetch_array($t);
$latt = $wto["lat"];
$lont = $wto["lon"];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-…
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<title>UT Campus Compass</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name = "viewport" content = "width = device-width">
<meta name="apple-mobile-web-app-capable" content="yes" />
<script src="http://maps.google.com/maps?file=ap…
type="text/javascript"></script>
<script type="text/javascript">
function midpoint() {
var lat2 = (<?php echo "$latf";?>) * (Math.PI/180);
var lat1 = (<?php echo "$latt";?>) * (Math.PI/180);
var dLon = (<?php echo "$lonf";?>-<?php echo "$lont";?>) * (Math.PI/180);
var Bx = Math.cos(lat2) * Math.cos(dLon);
var By = Math.cos(lat2) * Math.sin(dLon);
var lat3 = Math.atan2(Math.sin(lat1)+Math.sin(lat2)…
Math.sqrt( (Math.cos(lat1)+Bx)*(Math.cos(lat1)+Bx) + By*By) );
var lon3 = lon1 + Math.atan2(By, Math.cos(lat1) + Bx);
var lat4 = lat3 * (180/Math.PI);
var lon4 = lon3 * (180/Math.PI);
}
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canva…
map.setCenter(new GLatLng(lat4, lon4), 16);
var polyline = new GPolyline([
new GLatLng(<?php echo "$latf";?>, <?php echo "$lonf";?>),
new GLatLng(<?php echo "$latt";?>, <?php echo "$lont";?>)
], "#ff0000", 10);
map.addOverlay(polyline);
}
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<center>
<div id="map_canvas" style="width: 425px; height: 600px"></div>
<div id="message"></div>
</body>
</html>
<?php
ob_end_flush();
?>
任何帮助将不胜感激。
谢谢, 丹
【问题讨论】:
-
这里有问题吗?你需要什么帮助?我会编写 degToRad 和 radToDeg 函数,而不是多次编写相同的代码,但除此之外,你想要什么?
标签: php javascript