Hello, I've never dealt with GPS data before, but having a quick look at your code it looks like you have a mismatch in converting your data to and from integers and doubles.
I notice you multiply by 1E6 when extracting the lat/long, presumably this is to maintain some accuracy during the double to int conversion... int lat = (int) (currentPosition.getLatitude()*1E6); So one fix is to use all doubles and remove all of your *1E6. The other fix is to use /1E6 instead of *1E6 when converting back to doubles... currentPosition.setLatitude(smoothingCoor [0] / 1E6); instead of... smoothLat = (int) (smoothingCoor [0] * 1E6); currentPosition.setLatitude(smoothLat); I hope that fixes your issue. On Sunday, March 11, 2012 12:46:24 AM UTC-8, concave wrote: > > Hi guys, i've a little problem here. > I'm working with gps data, getting values every second and displaying > current position on a map. > The problem is that sometimes (specially when im using the app on > indoor and not make a move) the values vary a lot, making the current > position to change. > I was wondering about some easy enough method to avoid this. > As a first idea, I thought about discarding values with accuracy > beyond certain threshold, and use Exponential filtering as i use on my > Bearing. But i get up on Antartica. Here's the code that i used to get > the location and filtering it with exponential : > > public void onLocationChanged(Location newLocation) { > // Get previous Location, needed to get > the Bearing Value > if(currentPosition != null) > { > prevLocation = > currentPosition; > pLat = (int) > (prevLocation.getLatitude() *1E6); > pLongi = (int) > (prevLocation.getLongitude()*1E6); > > } > currentPosition = new Location > (newLocation); > int lat = (int) > (currentPosition.getLatitude()*1E6); > int longi = (int) > (currentPosition.getLongitude()*1E6); > > //Smoothing Latitude,Longitude > if(lat != 0 && longi != 0){ > coor[0] = lat; > coor[1] = longi; > if (smoothingCoor == null){ > smoothingCoor = coor; > } > for (i=0; > i<coor.length;i++){ > smoothingCoor[i] = > smoothingCoor [i] +alpha * (coor[i] - > smoothingCoor[i]); > } > smoothLat = (int) > (smoothingCoor [0] * 1E6); > smoothLongi = (int) > (smoothingCoor [1] * 1E6); > > > currentPosition.setLatitude(smoothLat); > > > currentPosition.setLongitude(smoothLongi); > > } > > // Get Bearing Value > if(prevLocation != null && currentPosition > != null){ > > bearing = > prevLocation.bearingTo(currentPosition); > > //Smoothing bearing value with exponential > if (smoothingBearing == 0) { > smoothingBearing = bearing; > } else { > smoothingBearing = smoothingBearing > +alpha * (bearing - > smoothingBearing); > } > > } > > Hope you can understand my explanataion, and i provide enough > information > Thanks -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en