【问题标题】:How to use my laptop as server如何将我的笔记本电脑用作服务器
【发布时间】:2014-08-06 16:43:01
【问题描述】:

我正在使用 GPS 我想在数据库中插入经度和纬度。在模拟器中它工作正常我将值插入数据库中,在移动设备中它不起作用,如何使用我的笔记本电脑作为服务器。我想插入经度和来自移动端的纬度正在使用网络服务(Json)。

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();
            }

    });
}

}

【问题讨论】:

  • 可能是因为没有找到10.0.2.2?在模拟器中它是本地的,但在设备中它有点不同
  • 您的笔记本电脑是否设置为接受 HTTP 请求?
  • 对不起,我是 android 的初学者。如何在笔记本电脑中设置接受 HTTP 请求?

标签: android gps


【解决方案1】:
  1. 在笔记本电脑上的 Eclipse 中安装 Apache Tomcat。
  2. 窗口 --> 显示视图 --> 服务器
  3. 在“服务器”选项卡中,右键单击 --> 新建服务器
  4. 选择服务器版本并配置服务器。
  5. 将动态 Web 项目添加到您的服务器并启动服务器。

如果您的服务器的 HTTP 端口是 8080 并且您的机器的 IP 地址是 172.25.5.25 并且如果应用程序 URL 是 hudson/firstApplication 并且如果 Web 服务路径是 getUserName

然后在您的移动应用中配置以访问以下 URL:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-12
    • 1970-01-01
    • 1970-01-01
    • 2020-09-27
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 2011-06-10
    相关资源
    最近更新 更多