2012-04-23 71 views
0

你好我想發送我的GPS座標和設備ID到服務器。我在我的服務器上工作,但只是想知道下面的代碼是否足以發佈座標..?通過使用JSON發送GPS座標到服務器

//get device id as following 
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); 
     String deviceid = telephonyManager.getDeviceId(); 



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


      HttpClient httpClient = new DefaultHttpClient(); 

      // Post method to send data to server 
      HttpPost post = new HttpPost(); 


      post.setURI(new URI("http://myserver.com/myphppage.php")); 

      // set your post data inside post method  
      post.setEntity(new StringEntity(postData)); 

      // execute post request here 
      HttpResponse response = httpClient.execute(post); 

回答

1

試試吧。

基本上它取決於您訪問服務器的模式(httphttps),但如果連接不安全,那就差不多了。

+0

將通過http訪問服務器 – 2012-04-23 05:51:32

相關問題