java


Android : GPS tracking system for find each other in a close area


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.
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.
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.
Here is my attempt.
My xml file:
<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" />
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();
}
}
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.
Thanks in advance.
You can use the following code if you have a server:
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.
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();
}
You will have to store these locations in sqlite database.Here is a tutorial on sqlite.
For gps tracking you can refer to this tutorial .
Note: But please make sure both devices have gps enabled .
EDIT
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.
Basic Idea :
1) Setup database (MySQL,SQL etc) in your server which have users table and location table which have thr locations data
2) In Android Create Service which will fire once in 15 minutes requesting current location.
3) Create SharedPreference / SQliteDB which holds the last Coordinates of the device which was also updated to the Server database.
4) If the current location matches the Last Location retrieved from the SharedPreference and/or around within proximity (depends on how much u give 30ft or more) then user is in the same place so don't upload the coordinates to the Server Database.
5) If the user isn't within proximity or last location doesn't match current location then upload the coordinates to the Server Database.
6) After uploading coordinates to the server, update SharedPreference too..
7) After uploaded coordinates, The Server must return the User details from its database who are within your proximity. Your app then knows who are near you and send notification to you saying "Your buddy XXX is nearby!"
8) In Server, after uploading your coordinates, The server will also send notification to the user who are nearby you using "Google Cloud Messaging".
9) Tips : Run a cron job in your server which will execute every minute and checks "Who is near to Who" and send notification to them.
Hope it helps somebody :)

Related Links

404 page when run as web application project
How to detect if two Strings in an array equal
LibGDX Table showing up too small on high DPI screens?
How to get an Array into Jlist
Output Arraylist String without brackets and commas
How to read in list objects to be serialized and deserialized using a different constructor?
Java - How Java decide where is infinity?
Read csv file with smooks
Build single Spring Boot WAR project for deployment
Dialog with email addresses
JavaFX: Access in FXML to a non-String-Object from a ResourceBundle
Auth filter in OSGi?
RESTful URLs with Jersey 2 subresources?
REST webservice using spring boot and jersey. Error: Validation of the application resource model has failed during application initialization
Spring boot App: appending a string to an existing txt file
How to modify a properties file in spring boot jar

Categories

HOME
log4j
wso2-am
image
netsuite
hashmap
lodash
office365api
syntax
android-4.4-kitkat
framework7
jsp-tags
yahoo-oauth
malloc
binary-tree
opengl-es-2.0
convolution
webrequest
google-translate
gnupg
izpack
postgres-xl
dtrace
windows-server-2012
clojurescript
after-effects
tostring
jsdoc
custom-wordpress-pages
reverse-proxy
cloudhub
dcevm
mmap
zurb-foundation-6
h2db
smb
fish
info.plist
fopen
windows-server-2000
webkitspeechrecognition
media-queries
directx-10
preg-match-all
webtest
avcapturesession
jmonkeyengine
revolution-slider
io-redirection
qwerty
mixture-model
streamsets
dynamic-reports
texmaker
jvm-languages
nand2tetris
import-from-excel
xml-documentation
upstart
celery-task
ionicons
datastax-startup
integrity
nstextview
mako
spring-mongodb
specrun
pintos
objective-c-swift-bridge
cubes
angular-strap
firmata
google-feed-api
angular-cache
adxstudio-portals
file-writing
mikroc
ctest
multiple-regression
apachebench
historian
jms2
sdhc
responsive-images
microbenchmark
apache-commons-fileupload
processmodel
sortedlist
mmc
google-style-guide
file-copying
titanium-modules
sgen
rebol3
viadeo
ivyde
ftps
ril
back-stack
qt-faststart
jquery-mobile-dialog
interface-orientation
eventlistener
trusted
first-responder
runas
frameset
parametric-equations
semantic-diff
work-stealing
table-footer
yslow
zend-translate
.nettiers
mozilla-prism
perfect-hash
substrings
xetex
boost-smart-ptr
zend-decorators

Resources

Encrypt Message