I have a google map fragment set up in my activity and an onLocationChanged() and getLastKnownLocation running in coherence with it.
However when i run my application , my map points to the right city and everything but the location is off from the original location by about a few km or so .
To understand why this was happening ,
I tried the following
1. Used the Button to reset the location with the location update
2. Logged my Location
3. Waited for the interval to reset my location
In all these cases my actual location was the end result either in the map or in the log with no significance of the fake location anywhere in the log .
So i set up a camera changed listener to understand the new location and acquire the coordinates but the coordinates it gave had a much higher precision than the original coordinates and im guessing somehow the problem arises when the coordinates are parametrised into the latlng class.
Ex:
Normal:
xx.xxxxxxx xx.xxxxxxx
Camera Changed Listener coordinates:
xx.xxxxxxxxxxxxxxx xx.xxxxxxxxxxxxxxx
Can anyone explain this?
Related
I'm currently doing some research about a very small app I wanna try building.
The core concept will consist of moving randomly spawned GPS Location objects closer to the Location of the user as time passes by.
I have been looking through the Location API and as I understand all I need to do is updating the altitude and latitude of the spawned Location object to change its position. Now I'm curious what the best method is to: "Move a Location closer to another Location by 10 meter".
Is there already some existing API that achieves that goal like this hypothetical function:
Location newLocation = Location.moveTo(Location locationFrom, Location locationTo, int distance);
or do I have to write my custom algorithm?
What would be an efficient approach in this case? Any inputs are highly appreciated!
If the problem would exist in a Cartesian coordinate system I would just substract the user Location from the spawned Location to get the direction I need to move too and then add parts of the new vector to the spawned Location to get it closer.
How can this get solved with Location's ?
EDIT: I sumbled upon this thread: Move a LatLng 5 meters towards another LatLng
I guess using SphericalUtil.java is the way to do it.
I have question about:
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, time, distance, locationListener);
I don't know how it's work, in this listener i have method onLocationChanged(Location location), but when listener call this method ? I have two variable, time in miliseconds and distance in meters, first variable tell when the location should be refresh, but we have second variable, and what ? Meybe it's working that, when the time(value from time variable) is gone, listener check distance between last postion and new position and if the distance between this positions is bigger than value from distance variable, listener will call onLocationChanged method. Right ? And i can use LocationListener for NETWORK_PROVIDER and for GPS_PROVIDER and it's works the same way. Right ? That this working ?
Time is your refresh interval i.e. location is refreshed by that amount of time. distance is the minimum change in distance in order to call onLocationChanged, basically these 2 parameters kinda filter the location you want. NETWORK and GPS provider more or less work same way, GPS is more accuracte but slow and network provider is less accurate and fast. You can check the accuracy on each location object though. So you are on the right track. Also check google play services location api which can be found here: https://developer.android.com/training/location/retrieve-current.html
I am developing an android application to track user movement over a Google map. I am using GPS to pull the user location. It works perfectly fine when I move over road and change my location continuously.
The issue is, when I stop and remain at a point (stops my movement) the GPS keep sending different GPS coordinates.
Please note that I am using GPS in open space and I have used -
Here is the location manager details I am using -
LocationManager locManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
criteria.setBearingAccuracy(Criteria.ACCURACY_LOW);
criteria.setSpeedAccuracy(Criteria.ACCURACY_HIGH);
String provider = locManager.getBestProvider(criteria, true);
locManager.requestLocationUpdates(provider,0,0, this);
Please let me know, if I am not using it properly.
I have also gone through various blogs and tutorials and learnt that GPS is not perfect at a single location. In that case how I will handle this situation. My aim is to get a single GPS while I am not moving and standing on a single position.
Please let me know.
Thank you !
RequestLocationUpdates method uses a float value for the third parameter, if you leave it at 0 it will continue to update even if you move a step or two. If you set it to a different number like 50.0 it will update every 50 metres.
I am using the new API V2, but that's probably not important since I am newbie for maps anyway:)
I have very simple need. I want to show my location and one target marker and all is working. It's just that the my location determination is not predictable, can get minutes or so to get the blue circle.
What I thought is to manually use the LocationManager to retreive in background the coarse or fine location and pass that value to the Mapactivity. Since normally the map activity will not start immediatelly it would work nice. Then I could also save to databse the last location and pass that in the case the map activity starts before the LocationManager get the real location.
I am looking at the api's but could not find a function that would display imemdiatelly the blue circle at given LatLong. Is this function available?
If this function is not available the only workaround that I could find is to override onlocationchanged to retrieve the new location and save the last, and to display the marker on last known mylocation (that would hide automatically itself on first locationchanged event).
But it would be easier, and also pretier, if I could simply pass initial mylocaltion coordiantes?
Thanks for any idea
I am looking at the api's but could not find a function that would display imemdiatelly the blue circle at given LatLong. Is this function available?
Use setLocationSource() to provide a LocationSource to the GoogleMap. Once your LocationSource is called with activate(), you will be handed a listener object, to which you can pass Location objects for the readings you get from a location provider.
I am using MyLocationOverlay to display the current location. However, it takes a while for the location to get updated. I wanted to implement something like the "follow me" feature on iPhone wherein the location of the user is also moving as the user moves. How can I make the marker of MyLocationOverlay to perform live update on its location?
Please note that I override the draw() and drawMyLocation() because I need to draw a custom marker.
My current code looks like this: (The problem with my code is that the marker does not move along with the user. Since it takes a while before onLocationChanged is called, the marker will just suddenly jump from one place to another.)
#Override
public synchronized void onLocationChanged(Location location)
{
if (location != null && mapController != null)
{
//Recenter map based on current location
mapController.animateTo(new GeoPoint((int) (location.getLatitude() * 1e6), (int) (location.getLongitude() * 1e6)));
}
super.onLocationChanged(location);
}
You can give location manager minimal interval to wait between calling that method, but it's not exactly going to mind that interval 100% of the time (see description of LocationManager.requestLocationUpdates()). Might be shorter, might be longer - because, e.g. it can be cloudy and gps chip won't be able to get location updates as regularly as you'd want it to.
There's no proper way to overcome this - location services will always have imperfections. Every location-aware app I used "hung" the marker from time to time because gps chip lost fix for a moment.
The only thing you can do to smooth this a bit is to remember the speed of movement and should gps lose fix give the map marker fake updates based on the assumption that the user is moving in the same direction with the same speed they were when gps had a fix. But it only makes sense to do that for like 2-5 skipped real updates (just to smooth the cases when fix is lost for several seconds).
UPD For that, you can implement kind of proxy location listener, which will update your marker strictly minding the intervals you specify, e.g. every 200 ms, and do so based on it's stored location. And the stored location can be asynchronously updated by the real location listener. Location objects have time of the fix that provided data (see getTime() method), you can use that to determine whether you should still "predict" next marker movement or the location is old enough to give up and notify user that gps has no clue where they are :)