安卓GPS跟踪系统,用于查找密切的区域彼此 [英] Android : GPS tracking system for find each other in a close area

查看:221
本文介绍了安卓GPS跟踪系统,用于查找密切的区域彼此的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要开发一个Android应用程序,此应用是应该做的就是帮助人们找到在一个封闭区域彼此不会浪费太多的权力。两个人都可以使用该应用程序与手机在他们的掌心朝上找到对方。它可以使用GPS来给出一个初始方向行驶(向前,向左,向右,向后)。然后,它可以使用蓝牙和WiFi的实力给用户他们是否越来越近或远的总体思路。它并不需要给电话之间的特定距离。

I have to develop an Android app, what this app is supposed to do is help people find each other in a close area without wasting too much power. Both people can use the app with the phone in their palm facing up to find each other. It can use gps to give an initial direction to travel(Forward, left, right, backwards). It can then use bluetooth and wifi strength to give the users a general idea of whether they are getting closer or farther. It does not need to give the specific distance between the phones.

我跟着这个( HTTP:// WWW .androidhive.info / 2012/07 / Android的GPS定位管理器教程/ )的教程,它工作正常。但我不知道如何在我的应用程序使用。

I've followed this(http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/) tutorial and it works fine. But I have no idea how to use this in my app.

我是开发Android应用的一个实习生,我是新来的GPS跟踪系统。其实我有关于如何启动这个程序没有明确的想法。

I am a trainee of developing Android applications and I am new to GPS tracking systems. Actually I have no clear idea about how to start this app.

下面是我的尝试。

我的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类

This is my MyService.java class

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类

And here is my MainActivity.java class

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>

此外,我可以得到每个设备的位置,但问题是我如何发送和两个设备之间接收这些数据。

Furthermore I can get the locations of each devices but the problem is how should I send and receive those data between two devices.

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

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

先谢谢了。

推荐答案

您可以使用以下code,如果你有一台服务器:

You can use the following code if you have a server:


  1. 您可以有一个 的服务在15个周期(运行一次分钟左右)。这种服务可以将设备的位置服务器以及获取朋友的设备。由于该服务会在后台定期运行将是有效的位置,并且不会消耗多少电。

  1. You can have a service running periodically (once in 15 mins or so ).This service can send the location of devices to the server as well fetch locations of friend's device .Since the service will run in periodically in background it will be efficient and will not consume much power.

此服务将检查每次如果有朋友是这样nearby.If通知可以generated.You可以使用以下方法来检查:

This service will check every time if any friend is nearby.If so a notification can be generated.You can use the following to check this :

public static float distBetweenTwoPoints(float lat1, float lng1,
        float lat2, float lng2) {
    // returns distance (in meters) between two points
    double earthRadius = 3958.75;
    double dLat = Math.toRadians(lat2 - lat1);
    double dLng = Math.toRadians(lng2 - lng1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
            + Math.cos(Math.toRadians(lat1))
            * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2)
            * Math.sin(dLng / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double dist = earthRadius * c;

    int meterConversion = 1609;

    return new Float(dist * meterConversion).floatValue();
}


  • 您可以将这些位置存储在SQLite数据库。这里是源码的教程。

    有关GPS跟踪,你可以参考这个教程

    For gps tracking you can refer to this tutorial .

    请注意:不过,请务必两台设备都支持GPS

    Note: But please make sure both devices have gps enabled .

    修改

    It can then use bluetooth and wifi strength to give the users a general idea of whether they are getting closer or farther
    

    只要你的服务检查的两个朋友都在附近(约蓝牙范围内)。您可以通过编程打开蓝牙并实现你想要做的事情。

    As soon as your service checks that two friends are nearby(within approx bluetooth range) .You can programmatically switch on bluetooth and implement what you wish to do.

    这篇关于安卓GPS跟踪系统,用于查找密切的区域彼此的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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