如何使用GoogleMap将当前位置存储到数据库中?

时间:2016-10-25 08:24:05

标签: android google-maps

如何使用GoogleMap将currentlocation存储到数据库?我正在使用一个url将currentlocation存储到数据库中....

https://182.50.133.175/dgrid55/15/index.php

.java文件

      URL url = null;
    try {
        url = new URL(strUrl);

        HttpURLConnection connection = (HttpURLConnection) url
                .openConnection();
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
                connection.getOutputStream());

        outputStreamWriter.write("latitude=" + lat + "&logitude="+lng);
        outputStreamWriter.flush();
        outputStreamWriter.close();

        InputStream iStream = connection.getInputStream();
        BufferedReader reader = new BufferedReader(new
                InputStreamReader(iStream));

        StringBuffer sb = new StringBuffer();

        String line = "";

        while( (line = reader.readLine()) != null){
            sb.append(line);
        }

        reader.close();
        iStream.close();

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

感谢adavace

1 个答案:

答案 0 :(得分:1)

如果您的服务器接受POST您可以在this回答:

中执行此操作
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("latitude", lat));
params.add(new BasicNameValuePair("logitude", lng));

然后

OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
        new OutputStreamWriter(os, "UTF-8"));
writer.write(getQuery(params));
writer.flush();
writer.close();
os.close();