Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用googlemapsapi检查XML_Php_Mysql_Google Maps - Fatal编程技术网

Php 使用googlemapsapi检查XML

Php 使用googlemapsapi检查XML,php,mysql,google-maps,Php,Mysql,Google Maps,在过去的几天里,我一直在玩谷歌地图API。由于缺乏PHP技能,我陷入了困境。运行下面的PHP代码后,返回的XML为: <?xml version="1.0"?> <markers/> 我使用的链接是: 我正在使用的代码来自: 我正在使用Dreamweaver来完成这个项目。如果有一种通过PHP代码进行调试的好方法,我将非常感激。我试着用谷歌搜索,但我不确定什么对一个PHP新手来说是最好的。 我检查了数据库中记录的半径。它们都在我测试坐标的50英里范围内 PHP代码是

在过去的几天里,我一直在玩谷歌地图API。由于缺乏PHP技能,我陷入了困境。运行下面的PHP代码后,返回的XML为:

<?xml version="1.0"?>
<markers/>

我使用的链接是:

我正在使用的代码来自:

我正在使用Dreamweaver来完成这个项目。如果有一种通过PHP代码进行调试的好方法,我将非常感激。我试着用谷歌搜索,但我不确定什么对一个PHP新手来说是最好的。 我检查了数据库中记录的半径。它们都在我测试坐标的50英里范围内

PHP代码是:

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

// Start XML file, create parent node
$doc = new DOMDocument("1.0");
$node = $doc->createElement("markers");
$parnode = $doc->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());
}

// Select all the rows in the markers table
$query = "SELECT user, latitude, longitude, ( 3959 * acos( cos( radians('%s') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( latitude ) ) ) ) AS distance FROM tbl_UserLatLng HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20";
$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)){
  // ADD TO XML DOCUMENT NODE
  $node = $doc->createElement("marker");
  $newnode = $parnode->appendChild($node);

  $newnode->set_attribute("user", $row['user']);
  $newnode->set_attribute("latitude", $row['latitude']);
  $newnode->set_attribute("longitude", $row['longitude']);
  $newnode->set_Attribute("distance", $row['distance']);
}

echo $doc->saveXML();

?>
createElement(“标记”);
$parnode=$doc->appendChild($node);
//打开到mySQL服务器的连接
$connection=mysql\u connect(localhost,$username,$password);
如果(!$connection){
die('未连接:'.mysql_error());
}
//设置活动mySQL数据库
$db\u selected=mysql\u select\u db($database,$connection);
如果(!$db_选中){
die('不能使用db:'.mysql_error());
}
//选择标记表中的所有行
$query=“选择用户、纬度、经度,(3959*acos(弧度('%s'))*cos(弧度(纬度))*cos(弧度(经度)-弧度('%s'))+sin(弧度('%s'))*sin(弧度(纬度)))作为与tbl_用户的距离,该用户与tbl_用户的距离按距离限制0,20的顺序小于'%s'”;
$result=mysql\u query($query);
如果(!$result){
die('无效查询:'.mysql_error());
}
标题(“内容类型:text/xml”);
//遍历行,为每个行添加XML节点
while($row=@mysql\u fetch\u assoc($result)){
//添加到XML文档节点
$node=$doc->createElement(“标记”);
$newnode=$parnode->appendChild($node);
$newnode->set_属性(“用户”,$row['user']);
$newnode->set_属性(“纬度”,$row['latitude']);
$newnode->set_属性(“经度”,$row['longitude']);
$newnode->set_属性(“距离”,$row['distance']);
}
echo$doc->saveXML();
?>

提前谢谢

尝试从mysql shell手动运行查询,查看显示的距离值。看起来你没有从数据库得到任何结果

SELECT user, latitude, longitude, 
    ( 3959 * acos( cos( radians('%s') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - 
    radians('%s') ) + 
    sin( radians('%s') ) * sin( radians( latitude ) ) ) ) AS distance 
FROM tbl_UserLatLng

你完全正确,但我不知道为什么Having条款不起作用。我不确定%s代表什么。从我查找的情况来看,它正在将任何数字/浮点数转换为字符串。如果您想这样做字符串替换:$query=sprintf(“选择bla bla%s”,myvalueToReplace)