problem on putting the value on parse.com

17 views
Skip to first unread message

Ashutosh Singh

unread,
May 28, 2015, 12:40:55 PM5/28/15
to android-...@googlegroups.com
Hello All,

I am developing a android app using parse.com as backend.  I am facing a problem when i put my current location (which is calculated by using geocoder) on parse.com it is refreshing 4/5 times in 1 second.i want to add only last known location.if i calculate the diffrence between current location and last known location and check if(lastknownlocation !=current location && difference is 5.0000 or something ) and put the location on server. it is adding a row when last latlang and current latlang are same.kindly please help me i am stuck on this point over last 10 days.

Thanks in advance !!!

Here is my code snippet           -

ParseGeoPoint point = new ParseGeoPoint(latitude, longitude);
double earthRadius = 3958.75;

if (lastLatLong == null) {
lastLatLong = latLng;
}
double dLat = Math.toRadians(latitude - lastLatLong.latitude);
System.out.println("Current lat..."+latitude);
System.out.println("Previous lat " + lastLatLong.latitude);
double dLng = Math.toRadians(longitude - lastLatLong.longitude);
System.out.println("Current lngt..."+longitude);
System.out.println("Previous longt " + lastLatLong.longitude);
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
+ Math.cos(Math.toRadians(lastLatLong.latitude))
* Math.cos(Math.toRadians(latitude)) * Math.sin(dLng / 2)
* Math.sin(dLng / 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double diff = earthRadius * c * 1609.00;

System.out.println("Diffrence is " + diff);
if (lastLatLong != latLng && diff >= 4.082382509737494) {
lastLatLong = latLng;
placeObject.put("location", point);
ParseUser currentUser = ParseUser.getCurrentUser();
placeObject.put("UserName", currentUser.getUsername());

ParseACL acl = new ParseACL();
acl.setPublicWriteAccess(true);
acl.setPublicReadAccess(true);
placeObject.setACL(acl);

placeObject.saveInBackground();

}
Reply all
Reply to author
Forward
0 new messages