Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7894565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:25:41+00:00 2026-06-03T07:25:41+00:00

I have two applications, one I send long. and latitude coordinates to a php

  • 0

I have two applications, one I send long. and latitude coordinates to a php file and the other application retrieves the long. and lat. coords. In order to test and see if I could get the first working I create a function I posted the latitude and long. coords two the php service and I got them back in the same Application. I placed them in a toast to see if it works. I even implemented location listener to upload the coordinates and retrieve them in the same application to test before trying to receive them in the other application. It works fine. But when I try to use the same code in the other application for receiving the coordinates, I receive blank coordinates. I debugged it and its just blank, as if when I make the call to the server from the other application it erases the current values in the php service.

Code for placing the coordinates in application one:

public void postData(String longCord, String latCord) throws JSONException{  
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(".../android/serverFile.php");
    JSONObject json = new JSONObject();

    try {
        // JSON data:
        json.put("longitude", longCord);
        json.put("latitude", latCord);
        JSONArray postjson=new JSONArray();
        postjson.put(json);

        // Post the data:
        httppost.setHeader("json",json.toString());
        httppost.getParams().setParameter("jsonpost",postjson);
        // Execute HTTP Post Request
        //System.out.print(json);
        HttpResponse response = httpclient.execute(httppost);

        // for JSON:
        if(response != null)
        {

            InputStream is = response.getEntity().getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            StringBuilder sb = new StringBuilder();
            String line = null;
            try {
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
                                    JSONObject jsonObj = new JSONObject(jsonStr);
                // grabbing the menu object 
                String longitudecord = jsonObj.getString("lon");
                String latitudecord = jsonObj.getString("lat");

                Toast.makeText( getApplicationContext(),longitudecord,Toast.LENGTH_SHORT).show();
                Toast.makeText( getApplicationContext(),latitudecord,Toast.LENGTH_SHORT).show();
        }

    }catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
}

php file:

<?php
$json = $_SERVER['HTTP_JSON'];
$data = json_decode($json);
$lon = $data->longitude;
$lat = $data->latitude;
$variable = array( 'lon' => "$lon", 'lat' => "$lat" );
// One JSON for both variables
echo json_encode($variable);

?>

Now when I run this code on the other application…Its the same as above minus posting the coordinates…I get lon:”” and lat:””. Sort of like by making the request it has somehow erased the info that was posted by other application. Is this the case?

 public void recieveData() throws JSONException{  
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(".../android/serverFile.php");
        try {
            HttpResponse response = httpclient.execute(httppost);
            // for JSON:
            if(response != null)
            {
                InputStream is = response.getEntity().getContent();
                BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                StringBuilder sb = new StringBuilder();
                String line = null;
                try {
                    while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        is.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                String jsonStr = sb.toString();
                JSONObject jsonObj = new JSONObject(jsonStr);
                // grabbing the menu object 
                String longitudecord = jsonObj.getString("lon");
                String latitudecord = jsonObj.getString("lat");

                Toast.makeText( getApplicationContext(),longitudecord,Toast.LENGTH_SHORT).show();
                Toast.makeText( getApplicationContext(),jsonStr,Toast.LENGTH_SHORT).show();
            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:25:42+00:00Added an answer on June 3, 2026 at 7:25 am

    Try to access your URL in browser and make sure your PHP script does not give any errors in the following lines (since you don’t supply any JSON input in the second application):

    $data = json_decode($json);
    $lon = $data->longitude;
    $lat = $data->latitude;
    

    Also, it would be nice to hear, how’d you save your lat/lon on the server, so they persist between the calls.

    For example, you may use this PHP code:

    $db_host = "localhost";
    $db_name = "********";
    $db_user = "********";
    $db_pass = "********";
    
    // connect to MySQL
    $db = mysql_connect($db_host, $db_user, $db_pass);
    if( !$db ) {
        die( 'Unable to connect to server : ' . mysql_error() );
    }
    
    // select the DB
    if( !mysql_select_db($db_name) ) {
        die( 'Unable to select DB : ' . mysql_error() );
    }
    
    // create table, if not exists
    if( !mysql_query( "CREATE TABLE IF NOT EXISTS `locations` (
        `id` int(11) NOT NULL auto_increment,
        `latitude` double NOT NULL COMMENT 'latitude',
        `longitude` double NOT NULL COMMENT 'longitude',
        PRIMARY KEY  (`id`)
        ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;"
    ) ) {
        die( 'Unable to create table : ' . mysql_error() );
    }
    
    // save values
    mysql_query( "INSERT INTO locations (`latitude`, `longitude`) VALUES ( '$lat', '$lon')" );
    
    // read them back
    $track = array()
    $result = mysql_query( "SELECT * FROM locations" );
    while( $data = mysql_fetch_assoc($result) ) {
        $track[] = array(
            'latitude' => $data['latitude'],
            'longitude' => $data['longitude'] );
    }
    
    // here you may convert `track` into JSON / XML and send coordinates list to your application
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have here two applications in two different projects in eclipse. One application (A)
I have two applications in my project 'test' the applications are one.mxml and two.mxml
i have two flex applications and i want to pass the data from one
I have two web applications running in the same Tomcat Instance. In one of
I run foo.com. I have two different applications that live in foo.com: one is
I have two window form applications written in C, one holds a struct consisting
I have two medium-sized web applications that I'm merging into one. They are both
I have two ASP.NET MVC web applications. One of them logs unhandled exceptions to
I have a project that generates applications for two targets. One of the targets
I have two windows application, one is a windows service which create EventWaitHandle and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.