如何使用XML查询RouteBox边界(来自PHP/MySQL)
我有一个MySQL数据库,可以动态转换为XML以查询RouteBox页面。我从Google示例开始所有这些页面。因此,为了获得我的XML,我有:如何使用XML查询RouteBox边界(来自PHP/MySQL),mysql,xml,bounds,Mysql,Xml,Bounds,我有一个MySQL数据库,可以动态转换为XML以查询RouteBox页面。我从Google示例开始所有这些页面。因此,为了获得我的XML,我有: <?php require("phpsqlajax_dbinfo.php"); // Get parameters from URL $center_lat = $_GET["lat"]; $center_lng = $_GET["lng"]; $radius = $_GET["radius"]; // Start XML fil
<?php
require("phpsqlajax_dbinfo.php");
// Get parameters from URL
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];
$radius = $_GET["radius"];
// 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 ($hostname_DB2, $username_DB2, $password_DB2);
if (!$connection) {
die("Not connected : " . mysql_error());
}
// Set the active mySQL database
$db_selected = mysql_select_db($database_DB2, $connection);
if (!$db_selected) {
die ("Can\'t use db : " . mysql_error());
}
// Search the rows in the markers table
$query = sprintf("SELECT id, address, name, lat, lng, type FROM markers");
$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", $row['name']);
$newnode->setAttribute("address", $row['address']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("id", $row['id']);
}
echo $dom->saveXML();
?>
createElement(“标记”);
$parnode=$dom->appendChild($node);
//打开到mySQL服务器的连接
$connection=mysql\u connect($hostname\u DB2、$username\u DB2、$password\u DB2);
如果(!$connection){
die(“未连接:”.mysql_error());
}
//设置活动mySQL数据库
$db\u selected=mysql\u select\u db($database\u DB2,$connection);
如果(!$db_选中){
die(“无法使用db:.mysql_error());
}
//搜索标记表中的行
$query=sprintf(“从标记中选择id、地址、名称、lat、lng、类型”);
$result=mysql\u query($query);
如果(!$result){
die(“无效查询:”.mysql_error());
}
标题(“内容类型:text/xml”);
//遍历行,为每个行添加XML节点
while($row=@mysql\u fetch\u assoc($result)){
$node=$dom->createElement(“标记”);
$newnode=$parnode->appendChild($node);
$newnode->setAttribute(“名称”,$row['name']);
$newnode->setAttribute(“地址”,$row['address']);
$newnode->setAttribute(“lat”,$row['lat']);
$newnode->setAttribute(“lng”,$row['lng']);
$newnode->setAttribute(“id”,$row['id']);
}
echo$dom->saveXML();
?>
类似地,我的RouteBox代码如下所示:
<!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" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Search Along a Route Example</title>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script src="/Test/Domain/src/RouteBoxer.js" type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var boxpolys = null;
var directions = null;
var routeBoxer = null;
var markers = [];
var infoWindow;
var locationSelect;
var distance = null; // km
function initialize() {
// Default the map view to the UK.
var mapOptions = {
center: new google.maps.LatLng(54.219218, -2.905669),
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoom: 6
};
map = new google.maps.Map(document.getElementById("map"), mapOptions);
routeBoxer = new RouteBoxer();
directionService = new google.maps.DirectionsService();
directionsRenderer = new google.maps.DirectionsRenderer({ map: map });
}
function route() {
// Clear any previous route boxes from the map
clearBoxes();
// Convert the distance to box around the route from miles to km
distance = parseFloat(document.getElementById("distance").value) * 1.609344;
var request = {
origin: document.getElementById("from").value,
destination: document.getElementById("to").value,
travelMode: google.maps.DirectionsTravelMode.DRIVING
}
// Make the directions request
directionService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsRenderer.setDirections(result);
// Box around the overview path of the first route
var path = result.routes[0].overview_path;
var boxes = routeBoxer.box(path, distance);
drawBoxes(boxes);
} else {
alert("Directions query failed: " + status);
}
});
}
// Draw the array of boxes as polylines on the map
function drawBoxes(boxes) {
boxpolys = new Array(boxes.length);
for (var i = 0; i < boxes.length; i++) {
boxpolys[i] = new google.maps.Rectangle({
bounds: boxes[i],
fillOpacity: 0,
strokeOpacity: 1.0,
strokeColor: '#000000',
strokeWeight: 1,
map: map
//Perform Search
});
}
}
// Clear boxes currently on the map
function clearBoxes() {
if (boxpolys != null) {
for (var i = 0; i < boxpolys.length; i++) {
boxpolys[i].setMap(null);
}
}
boxpolys = null;
}
</script>
<style>
#map {
border: 1px solid black;
}
</style>
</head>
<body onload="initialize();">
<div id="map" style="width: 800px; height: 600px;"></div>
Box within at least <input type="text" id="distance" value="5" size="2">miles
of the route from <input type="text" id="from" value="tacoma"/>
to <input type="text" id="to" value="seattle"/>
<input type="submit" onclick="route()"/>
</body>
</html>
Google将JavaScript API搜索映射到一个路由示例
var-map=null;
var-boxpolys=null;
var方向=null;
var routeBoxer=null;
var标记=[];
var信息窗口;
变量位置选择;
var distance=null;//km
函数初始化(){
//默认地图视图为英国。
变量映射选项={
中心:新google.maps.LatLng(54.219218,-2.905669),
mapTypeId:google.maps.mapTypeId.ROADMAP,
缩放:6
};
map=new google.maps.map(document.getElementById(“map”)、mapOptions);
routeBoxer=新的routeBoxer();
directionService=new google.maps.directionService();
directionsRenderer=new google.maps.directionsRenderer({map:map});
}
函数路径(){
//从地图中清除所有以前的路线框
ClearBox();
//将路线周围的距离从英里转换为公里
距离=parseFloat(document.getElementById(“距离”).value)*1.609344;
var请求={
来源:document.getElementById(“from”).value,
目标:document.getElementById(“to”).value,
travelMode:google.maps.Directions travelMode.DRIVING
}
//提出指示要求
路由(请求、功能(结果、状态){
if(status==google.maps.directionstatus.OK){
directionsRenderer.setDirections(结果);
//第一条路线的概览路径周围的框
var path=result.routes[0]。概述\u路径;
变量框=路由框(路径、距离);
抽屉(盒);;
}否则{
警报(“方向查询失败:+状态”);
}
});
}
//将长方体阵列绘制为地图上的多段线
功能抽丝盒(盒){
boxpolys=新数组(box.length);
对于(变量i=0;i
那么,如何将我的项目发送到RouteBox中的apepar?如何将RouteBox的边界发送到xml进行查询?或者,从另一个角度看,如何让RouteBox查询xml并仅返回边界内的项目
我很困惑