Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have been trying to display the gps coordinated to a web server since several days but havent come to any conclusion yet. What i am trying to do is to get the latitudes and longitudes of a person and then display them on the webserver. I got a php server and mysql database. There is no error but There is nothing displayed on the url

public class UseGps extends Activity 

{ 


/** Called when the activity is first created. */ 

@Override 

public void onCreate(Bundle savedInstanceState) 

{ 

super.onCreate(savedInstanceState); 

setContentView(R.layout.main); 



/* Use the LocationManager class to obtain GPS locations */ 

LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 

LocationListener mlocListener = new MyLocationListener(); 



mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener); 



} 



/* Class My Location Listener */ 

public class MyLocationListener implements LocationListener 

{ 
 Context context;
 public void onLocationChanged(Location loc) 

{ 


double latitude = loc.getLatitude(); 

double longitude = loc.getLongitude(); 
Toast.makeText(context, "Latitude:" +latitude + "Longitude:" +longitude, 5000).show();
TelephonyManager telephonyManager =    (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String Devid = telephonyManager.getDeviceId();




//this is JSON part to put your information inside it
String postData = "{"request":{"type":"locationinfo"},"userinfo":{"Devid":""+Devid+"","latitude":""+latitude+"","longitude":""+longitude+""}}";

Uri uri = Uri.parse("http://location.site88.net/store.php"); 
Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
startActivity(intent); 
String url="http://location.site88.net/storeg.php"; 

DefaultHttpClient httpClient = new DefaultHttpClient(); 
HttpPost httpPost = new HttpPost(url); 

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("Devid", Devid));
nameValuePairs.add(new BasicNameValuePair("latitude", Double.toString(latitude) )); 
nameValuePairs.add(new BasicNameValuePair("longitude", Double.toString(longitude))); 

try {
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} 
HttpResponse httpResponse = null;
String result = null;
try {
    httpResponse = httpClient.execute(httpPost);
    HttpEntity httpEntity = httpResponse.getEntity();
    if (httpEntity != null) {
        InputStream instream = null;
        instream = httpEntity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(instream,"iso-8859-1"),8); 
        StringBuilder sb = new StringBuilder(); 
        String line = null; 
        while ((line = reader.readLine()) != null) { 
            sb.append(line + "
"); 
            Toast.makeText(getApplicationContext(), "pass", Toast.LENGTH_SHORT).show(); 
        } 
         instream.close();
              result=sb.toString(); 
      }
} catch (ClientProtocolException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} 
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub

}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub

}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub

  }}}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
105 views
Welcome To Ask or Share your Answers For Others

1 Answer

use

nameValuePairs.add(new BasicNameValuePair("latitude", Double.toString(latitude) )); 
nameValuePairs.add(new BasicNameValuePair("longitude", Double.toString(longitude))); 
nameValuePairs.add(new BasicNameValuePair("devid", devid)); 
try {
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} 
HttpResponse httpResponse = null;
try {
    httpResponse = httpClient.execute(httpPost);
    HttpEntity httpEntity = httpResponse.getEntity();
    if (httpEntity != null) {
        InputStream instream = null;
        instream = httpEntity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(instream,"iso-8859-1"),8); 
        StringBuilder sb = new StringBuilder(); 
        String line = null; 
        while ((line = reader.readLine()) != null) { 
            sb.append(line + "
"); 
            Toast.makeText(getApplicationContext(), "pass", Toast.LENGTH_SHORT).show(); 
        } 
         instream.close();
              result=sb.toString(); 
      }
} catch (ClientProtocolException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} 

instead of

HttpResponse Response = httpClient.execute(httpPost); 
InputStream httpEntity = httpResponse.getEntity().getContent(); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...