简体   繁体   中英

Retrieving data in android from mysql database

I have an android app which will send location information(lat and lon values) to mysql database using php script.

Following is my php script:

<?php
    ob_start();

    $host="localhost"; // Host name 
    $username=""; // Mysql username 
    $password=""; // Mysql password 
    $db_name="test"; // Database name 
    $tbl_name="map"; // Table name 

    $message=$_POST['a'];
    $message1=$_POST['b'];

    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");

    $query = "INSERT INTO map(id,longitude,latitude)VALUES(DEFAULT,'".$_REQUEST['message']."', '".$_REQUEST['message1']."')";
    mysql_query($query) or die(mysql_error("error"));
    mysql_close();
?>

MySQL database has the following fileds,

+----+----------+-----------+
| id | latitude | longitude |
+----+----------+-----------+

These things works fine.

My question is "I need to retrieve the table values from MYSQL(lat and lon values) using android app.

And from those lat and lon values I need to draw a map using android map to trace the location which I travelled.

Storing values in database works fine. I need help/idea to retrieve data from database and draw map using that in android.

Its not a good idea to read the data from MYSQL through Android. Please use webservices for this. You can use Resful webservice with JSON data (webservice in php and the JSON will be consumed in Android).

use this link...to get the value from mysql database..

http://blog.sptechnolab.com/2011/02/10/android/android-connecting-to-mysql-using-php/

Hey why don't you write Webservice to read from the MySQL DB. You can use PHP for writing webservice .

And can use kSOAP library to consume the JSON webservice. Use this guide if you are unable to get started with the library.

Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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