upload Data with Geo location : Location « Hardware « Android






upload Data with Geo location

 

//package usar.mobile;

import android.location.Location;
import android.util.Log;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

class DataTransferUtil {
  public static void uploadData(Location location) {
    
    String url = "http://urbansearchrescue.appspot.com/upload";

    HttpClient httpclient = new DefaultHttpClient();

    HttpPost httpPost = new HttpPost(url);

    try {
      
        if (location == null) {
          return;
        }
        
        double longitude = location.getLongitude();
        double latitude = location.getLatitude();
      
        //ResponseHandler <String> res = new BasicResponseHandler(); 
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("x_coord", Double.toString(longitude)));    
        nameValuePairs.add(new BasicNameValuePair("y_coord", Double.toString(latitude)));    
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));    
         

        Log.v("DataTransferUtil",
                "executing request " + httpPost.getRequestLine());

        HttpResponse response = httpclient.execute(httpPost);
    } catch (UnsupportedEncodingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClientProtocolException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }

}

   
  








Related examples in the same category

1.Location service and LocationManager
2.Location service
3.Using LocationManager
4.My location
5.Display GEO location
6.Using location service for the weather
7.Using Intent to go to a geo location
8.Location based service
9.My location and Google Map
10.Custom Location Overlay
11.Get my location
12.Geo location and Google Map
13.Location Tracking
14.A light pool of objects that can be resused to avoid allocation.
15.extends android.location.Location
16.Geo Location Util
17.C:\Java_Dev\WEB\dev\android\weatherforecastsystem-read-only\com\hci\pwf\LocationUtil.java
18.Copy a file from one location to another.
19.LocationManager.GPS_PROVIDER
20.Location util