douqingji3026 2016-08-15 14:56
浏览 13

没有输入数据库

I want to upload the longitude and latitude from my locationlistener every 5 seconds to my database. I dont know why but i cant connect to it or something else goes wrong. I dont got any errors. I put the latitude and longitude double to a String.

If you can help me guys this would be so great!

RequestQueue requestQueue; String insertUrl = "http://10.0.2.2/insertlocation.php";

...

And i put this in the oncreate method: requestQueue = Volley.newRequestQueue(getApplicationContext());

...

@Override
    public void onLocationChanged(Location location) {

        if (location == null)
            return;

        mPositionMarker = mMap.addMarker(new MarkerOptions()
                .flat(true)
                .icon(BitmapDescriptorFactory
                        .fromResource(R.drawable.motorcycle))
                .anchor(0.5f, 1f)
                .position(new LatLng(location.getLatitude(), location.getLongitude())));

        final double latitude = location.getLatitude();
        final double longitude = location.getLongitude();
        String Text = latitude + " " + longitude;
        //Toast.makeText(this, Text, Toast.LENGTH_SHORT).show();
        Log.d("location changed lat", location.getLatitude()+" long: "+location.getLongitude());


        StringRequest request = new StringRequest(Request.Method.POST, insertUrl, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Toast.makeText(Karte.this, "Connected", Toast.LENGTH_SHORT).show();
            }


        }, new Response.ErrorListener() {


            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(Karte.this, "Not Connected", Toast.LENGTH_SHORT).show();

            }
        }){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String,String> parameters = new HashMap<String, String>();
                String lat2string = String.valueOf(latitude);
                String long2string = String.valueOf(longitude);

                parameters.put("longitude", long2string);
                parameters.put("latitude", lat2string);

                return parameters;
            }
        };
        requestQueue.add(request);
    }

insertlocation.php

<?php

if($_SERVER["REQUEST_METHOD"]=="POST"){
    require 'connection.php';
    createLocation();
}

function createlocation()
{
    global $connect;

    $latitude = $_POST["latitude"];
    $longitude = $_POST["longitude"];

    $query = " Insert into user_info(latitude,longitude) values ('$latitude','$longitude');";

    mysqli_query($connect, $query) or die (mysqli_error($connect));
    mysqli_close($connect);

}

?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算