Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用我的笔记本电脑作为服务器_Android_Gps - Fatal编程技术网

Android 如何使用我的笔记本电脑作为服务器

Android 如何使用我的笔记本电脑作为服务器,android,gps,Android,Gps,我使用GPS我想在数据库中插入经度和纬度。在emulator中,它工作正常。我正在获取插入数据库中的值,在mobile中,它不工作,如何将我的笔记本电脑用作服务器。我想使用web服务(Json)从mobile中插入经度和纬度 } 在您的eclipse中安装ApacheTomcat,可在笔记本电脑中使用 窗口-->显示视图-->服务器 在“服务器”选项卡中,右键单击-->新建服务器 选择服务器版本并配置服务器 将动态web项目添加到服务器并启动服务器 如果服务器的HTTP端口为8080,计算机的I

我使用GPS我想在数据库中插入经度和纬度。在emulator中,它工作正常。我正在获取插入数据库中的值,在mobile中,它不工作,如何将我的笔记本电脑用作服务器。我想使用web服务(Json)从mobile中插入经度和纬度

}

  • 在您的eclipse中安装ApacheTomcat,可在笔记本电脑中使用
  • 窗口-->显示视图-->服务器
  • 在“服务器”选项卡中,右键单击-->新建服务器
  • 选择服务器版本并配置服务器
  • 将动态web项目添加到服务器并启动服务器
  • 如果服务器的HTTP端口为
    8080
    ,计算机的IP地址为
    172.25.5.25
    ,应用程序URL为
    hudson/firstApplication
    ,并且Web服务路径为
    getUserName

    然后在移动应用程序中配置以点击以下URL:


    http://172.25.5.25:8080/hudson/firstApplication/getUserName

    可能是因为它找不到10.0.2.2?在emulator中,它是本地的,但在设备上有点不同。您的笔记本电脑是否已设置为接受HTTP请求?对不起,我是android的初学者。如何设置在笔记本电脑中接受HTTP请求?
    public class AndroidGPSTrackingActivity extends Activity
        {
        public double latitude;
        public double longitude;
        Button btnShowLocation;
        GPSTracker gps;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        btnShowLocation = (Button) findViewById(R.id.btnShowLocation);
    
        // show location button click event
        btnShowLocation.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View arg0) {        
                // create class object
                gps = new GPSTracker(AndroidGPSTrackingActivity.this);
    
                // check if GPS enabled     
                if(gps.canGetLocation()){
    
                     latitude = gps.getLatitude();
                    longitude = gps.getLongitude();
    
                    // \n is for new line
                     String Text = "My current Latitude = " + latitude  + " Longitude = " + longitude;
    
                     Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();   
    
                     SendQueryString();
                }else{
                    // can't get location
                    // GPS or Network is not enabled
                    // Ask user to enable GPS/network in settings
                    gps.showSettingsAlert();
                }
    
    
    
            }
             public void SendQueryString() {
                    new Thread() {  
                        public void run() {
    
                            String url = "http://10.0.2.2/jobsonthego/jobs/gps.php?latitude=" + latitude +"&longitude=" + longitude;
                            //String url = "http://10.0.2.2/android/gps.php";
                            try {
                                HttpClient Client = new DefaultHttpClient();
                                HttpGet httpget = new HttpGet(url);
                                Client.execute(httpget);
                            }
                            catch(Exception ex) {
                                String fail = "Fail!";
                                Toast.makeText( getApplicationContext(),fail,Toast.LENGTH_SHORT).show();
                            }
                        }
                    }.start();
                }
    
        });
    }