使用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();
}
});
}
}
答案 0 :(得分:0)
如果您的服务器的HTTP端口是8080
且您的计算机的IP地址是172.25.5.25
,并且应用程序网址是hudson/firstApplication
,并且网站是服务路径为getUserName
,
然后在您的移动应用中配置以点击以下网址:
http://172.25.5.25:8080/hudson/firstApplication/getUserName