GPS跟踪系统,用于发现对方在一场势均力敌的区域 - Android电子 [英] GPS tracking system for find each other in a close area - Android

查看:109
本文介绍了GPS跟踪系统,用于发现对方在一场势均力敌的区域 - Android电子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发应在密切的区域发现对方的能力,一个Android应用程序。我已经张贴描述所有要求的问题。请看(<一href=\"http://stackoverflow.com/questions/20321620/android-gps-tracking-system-for-find-each-other-in-a-close-area\">Android :GPS跟踪系统,用于发现对方在一场势均力敌的区域)

I am developing an android application which should has the capability of finding each other in a close area. I've posted a question which describes all the requirements. Please look at (Android : GPS tracking system for find each other in a close area)

我使用的是服务,但我不知道如何(在15分钟左右一次)定期运行该服务。同时,我对如何设备的位置发送给服务器,以及如何获取朋友的设备的位置没有明确的想法。

I am using a service but I don't know how to run this service periodically (once in 15 mins or so ). And also I have no clear idea about how to send the location of devices to the server and how to fetch locations of friend's device.

下面是我的尝试。

我的xml文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/button1"
    android:layout_alignBottom="@+id/button1"
    android:layout_alignParentRight="true"
    android:onClick="stopNewService"
    android:text="Stop Service" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="23dp"
    android:onClick="startNewService"
    android:text="Start Service" />

这是我的 MyService.java

package com.example.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;

public class MyService extends Service {

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public void onCreate() {
    Toast.makeText(this, "The new Service was Created", Toast.LENGTH_LONG)
            .show();

}

@Override
public void onStart(Intent intent, int startId) {
    // For time consuming an long tasks you can launch a new thread here...
    Toast.makeText(this, " Service Started", Toast.LENGTH_LONG).show();

}

@Override
public void onDestroy() {
    Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();

}

}

和这里是我的 MainActivity.java

package com.example.service;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity implements View.OnClickListener {
private Button bStart, bStop;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

// Start the service
public void startNewService(View view) {

    startService(new Intent(this, MyService.class));
}

// Stop the service
public void stopNewService(View view) {

    stopService(new Intent(this, MyService.class));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.button1:
        startNewService(v);

        break;
    case R.id.button2:
        stopNewService(v);

        break;

    default:
        break;
    }
}

}

我已经添加了服务于清单文件。

I've added the service into manifest file.

<service android:name=".MyService"></service>

我会更感激,如果有人请这么好心地帮我澄清这一点。

I would be much thankful if anyone please be so kind enough to help me to clarify this.

先谢谢了。

推荐答案

有关的服务,您可以使用的 AlarmManager 处理器

For the service, you can use an AlarmManager or a Handler.

对于取/发送数据,你必须有位于某处的服务器(不知道你是不是与服务器部分入门,但是你可以要求/事后给出更多的信息)。我与服务器最好的办法是创建一个Web服务(WCF休息),并用它通过AsyncTask的(JSON)从任何Android设备进行通信。

As for the fetching/sending of data, you have to have a server located somewhere (not sure what you are not getting with the server part, but you can ask for/give more information afterwards). My best bet with the server is creating a web service (WCF Rest) and communicating with it via AsyncTask (JSON) from any Android device.

这篇关于GPS跟踪系统,用于发现对方在一场势均力敌的区域 - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆