-1

How can i store currentlocation into database using GoogleMap?I am using one url for storing currentlocation into database....

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

.java file

      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();
    }

Thanks in adavace

Roman Pokrovskij
  • 9,449
  • 21
  • 87
  • 142
Adam
  • 444
  • 5
  • 18

1 Answers1

1

If your server accept POST You can do that like in this answer:

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("latitude", lat));
params.add(new BasicNameValuePair("logitude", lng));

then

OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
        new OutputStreamWriter(os, "UTF-8"));
writer.write(getQuery(params));
writer.flush();
writer.close();
os.close();
Community
  • 1
  • 1
Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
  • Without Json can i store data to databse? – Adam Oct 25 '16 at 09:22
  • It depends on server-side implementation. – Andrii Omelchenko Oct 25 '16 at 09:23
  • Can i store my Google map Current Location in database(MySQL) without webservice? – Adam Oct 25 '16 at 09:26
  • 1
    No. You should have something, which receives your data from request ans stores it in appropriate database fields. – Andrii Omelchenko Oct 25 '16 at 09:29
  • 1
    Is webservices compulsory for current location store in database? – Adam Oct 25 '16 at 10:01
  • That is different question. When You sent some data from your app what will receive it? What will parse it and creates INSERT INTO query for MySQL? So You need some server-side code for receiving, process and store data. It can be php, python, java or other language script. You can take a look at [this](http://people.cs.ksu.edu/~hankley/d764/tut06/GopisettyPHP.html) tutorial (instead of the web form will be your Android application) – Andrii Omelchenko Oct 25 '16 at 10:12