Javascript 将HTTP post数据从Android应用程序发送到html中包含PHP的服务器

Javascript 将HTTP post数据从Android应用程序发送到html中包含PHP的服务器,javascript,php,android,html,google-maps-api-3,Javascript,Php,Android,Html,Google Maps Api 3,所以我最近开发了一个android应用程序,它涉及GPS定位。然后,我在服务器端使用PHP设置应用程序,定期将其位置发送到服务器。最初,我只是将PHP代码放在自己的文件中,PHP代码写入index.html,然后由apache服务器显示。今天,我决定试用GoogleMapsJavaScriptAPI,并尝试使用应用程序中的位置数据在GoogleMap上设置标记。虽然映射工作正常,但php代码似乎没有接收HTTP post数据,或者如果接收到HTTP post数据,它也没有对其执行任何操作。 这是

所以我最近开发了一个android应用程序,它涉及GPS定位。然后,我在服务器端使用PHP设置应用程序,定期将其位置发送到服务器。最初,我只是将PHP代码放在自己的文件中,PHP代码写入index.html,然后由apache服务器显示。今天,我决定试用GoogleMapsJavaScriptAPI,并尝试使用应用程序中的位置数据在GoogleMap上设置标记。虽然映射工作正常,但php代码似乎没有接收HTTP post数据,或者如果接收到HTTP post数据,它也没有对其执行任何操作。
这是我的index.html文件,我在其中组合了所有html、php和JavaScript代码

<html>
<?php
// get the "message" variable from the post request
// this is the data coming from the Android app
$latitude = $_POST["Latitude"];
$longitude = $_POST["Longitude"];
$dateTime = date('m:d:y g:i:s');
?>
<title>Find My Location</title>
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0; padding: 0 }
  #map-canvas { height: 100% }
  #map-canvas { width: 100% }
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=(My api key removed for privacy)">
</script>
<script type="text/javascript">
var latitude = '<?=$latitude?>';
var longitude = '<?=$longitude?>';
var dateTime = '<?=$dateTime?>';
var fmlLatLng = new google.maps.LatLng(latitude, longitude);
  function initialize() {
    var mapOptions = {
      center: new google.maps.LatLng(29.6520, -82.3250),
      zoom:10
    };
    var map = new google.maps.Map(document.getElementById("map-canvas"),
        mapOptions);
    if (!isNaN(fmlLatLng.lat()) && !isNaN(fmlLatLng.lng())){
    var marker = new google.maps.Marker({
            position: fmlLatLng,
            map: map,
            title: 'Hello World!'

     });
       google.maps.event.addListener(marker, 'click', function() {
            alert(dateTime);

     });
    }

    }
  google.maps.event.addDomListener(window, 'load', initialize);
</script>
<body>
<head><strong>Recent Locations</strong></head>
<div id="map-canvas"/>
</body>
</html>

找到我的位置
html{高度:100%}
正文{高度:100%;边距:0;填充:0}
#地图画布{高度:100%}
#地图画布{宽度:100%}
var纬度=“”;
var经度=“”;
var dateTime='';
var fmllalng=新的google.maps.LatLng(纬度、经度);
函数初始化(){
变量映射选项={
中心:新google.maps.LatLng(29.6520,-82.3250),
缩放:10
};
var map=new google.maps.map(document.getElementById(“地图画布”),
地图选项);
如果(!isNaN(fmllalng.lat())和&!isNaN(fmllalng.lng()){
var marker=new google.maps.marker({
位置:FML,
地图:地图,
标题:“你好,世界!”
});
google.maps.event.addListener(标记'click',函数(){
警报(日期时间);
});
}
}
google.maps.event.addDomListener(窗口“加载”,初始化);
最近的地点
这是我的android应用程序中用来发送数据的代码

 if (currentLocation == null) {
                                return;
                            } else {

                                //Creating strings for the latitude and longitude values of our current location
                                String latitude = new String(" " + currentLocation.getLatitude());
                                String longitude = new String(" " + currentLocation.getLongitude());

                                // Creating an http client and http post object in order to interact with DFLGNVLAB01 server
                                HttpClient httpclient = new DefaultHttpClient();
                                HttpPost httppost = new HttpPost("http://findmylocation.chandlermatz.com/index.html");
                                try {

                                    //Creating identifier and value pairs for the information we want to send to DFLGNVLAB01
                                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                                    nameValuePairs.add(new BasicNameValuePair("Latitude", latitude));
                                    nameValuePairs.add(new BasicNameValuePair("Longitude", longitude));

                                    //Sending data to DFLGNVLAB01 via http client
                                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                                    httpclient.execute(httppost);
                                } catch (ClientProtocolException e) {

                                } catch (IOException e) {

                                }
                            }
if(currentLocation==null){
返回;
}否则{
//为当前位置的纬度和经度值创建字符串
字符串纬度=新字符串(“+currentLocation.getLatitude());
字符串经度=新字符串(“+currentLocation.getLength());
//创建http客户端和http post对象以便与DFLGNVLAB01服务器交互
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(“http://findmylocation.chandlermatz.com/index.html");
试一试{
//为要发送到DFLGNVLAB01的信息创建标识符和值对
List nameValuePairs=新的ArrayList(2);
添加(新的BasicNameValuePair(“纬度”,纬度));
添加(新的BasicNameValuePair(“经度”,经度));
//通过http客户端向DFLGNVLAB01发送数据
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
}捕获(客户端协议例外e){
}捕获(IOE异常){
}
}
提前感谢您提供的任何帮助

使用

找到我的位置
html{高度:100%}
正文{高度:100%;边距:0;填充:0}
#地图画布{高度:100%}
#地图画布{宽度:100%}
var纬度=“”;
var经度=“”;
var dateTime='';

如果您提醒您的post值,它们是否有值?警报(纬度)@马特不,当我提醒他们说的都是。所以我猜我把变量从php代码转移到java代码可能是错误的?顺便说一句,尽量不要用这个:'显然我的同事是对的;)@我试着把每个变量都改成var latitude=;,但现在地图根本不加载
<html>
<?php
// get the "message" variable from the post request
// this is the data coming from the Android app
$latitude = $_POST["Latitude"];
$longitude = $_POST["Longitude"];
$dateTime = date('m:d:y g:i:s');
?>
<title>Find My Location</title>
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0; padding: 0 }
  #map-canvas { height: 100% }
  #map-canvas { width: 100% }
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=(My api key removed for privacy)">
</script>
<script type="text/javascript">
var latitude = '<?php echo $latitude; ?>';
var longitude = '<?php echo $longitude; ?>';
var dateTime = '<?php echo $dateTime; ?>';