简体   繁体   English

使用PHP从服务器获取经度和纬度

[英]Getting latitude and longitude from server using PHP

I am trying to build an Android app which queries a server to get the latitude and longitude for the given destination. 我正在尝试构建一个Android应用程序,该应用程序查询服务器以获取给定目的地的纬度和经度。 However there seems to be an error in my PHP code as it shows the following error when I input the address in the web browser. 但是,我的PHP代码中似乎有一个错误,因为当我在Web浏览器中输入地址时,它显示了以下错误。

Notice: Undefined variable: destination in C:\xampp\htdocs\serverfiles\btc.php on line 6
{"result":[{"latitude":null,"longitude":null}]}

This is my btc.php file: 这是我的btc.php文件:

<?php
if($_SERVER['REQUEST_METHOD']=='GET'){
$id  = $_GET['destination'];
$con = mysqli_connect("127.0.0.1", "root", "", "bustrack");

$sql = "SELECT * FROM updates WHERE destination='".$destination."'";
$r = mysqli_query($con,$sql);
$res = mysqli_fetch_array($r);
$result = array();
array_push($result,array(
"latitude"=>$res['latitude'],
"longitude"=>$res['longitude'],
)
);
echo json_encode(array("result"=>$result));
}

$sql = "SELECT * FROM updates WHERE destination='".$destination."'"; The variable $destination does not exist. 变量$destination不存在。 You need to declare it before using it. 您需要先声明它,然后再使用它。 I believe the variable $id is what you want, looking to your code. 我相信变量$id是您想要的,并查看您的代码。

This issue is that you never assign $destination a variable: 这个问题是您永远不会$destination分配变量:

$id  = $_GET['destination'];
$con = mysqli_connect("127.0.0.1", "root", "", "bustrack");

$sql = "SELECT * FROM updates WHERE destination='".$destination."'";

You should do this: 你应该做这个:

$id  = $_GET['destination'];
$con = mysqli_connect("127.0.0.1", "root", "", "bustrack");

$sql = "SELECT * FROM updates WHERE destination='".$id."'";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM