我创建了一个应用程序,它可以为您提供位置和其他位置。当应用程序出现在两部手机上时,只有他们可以跟踪其他人。我使用WAMP创建了一个服务器。我如何连接服务器和我做的这个应用程序。想为它添加一些功能: - 1.我想将gps的坐标发送到服务器。并且还更新位置。 2.在服务器端,我也想显示所有人都在使用它和他们的坐标。请帮我解释一下代码..
答案 0 :(得分:1)
简单方法
将HttpConnection
用于您的服务器,并将位置坐标与设备ID放在发布数据中。并将此数据发送到您的服务器。设备ID将标识正在使用该应用程序的用户。在发布数据中,您可以使用JSON
或XML
将您想要的值设置为设备ID,位置坐标以及更多您想要的内容。
//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);