This might be a noob question for some of you. I want to create an action for android application where if someone is close to some certain location using geopoint and i want to verify this using mylocation to create an action which will location aware. Any idea ??
You could hold the location you want to reach in a Location object,
and then every time location gets update from the GPS, or every few seconds or so, check ths distance to it. and if it's smaller than a given value, you're there.
check this out
http://advback.com/android/finding-distance-between-two-points-with-google-maps-android/
EDIT:
Since you mentioned you want to use GeoPoint, here's a quick explanation on how to convert between the two:
Convert GeoPoint to Location
Related
Is it possible to ensure that the location indicator doesn't keep pointing back to the route while you are deviating from it? It makes it very hard to see what's in front of the user as when camera tracking mode is turned on, it locks the camera to the location indicator's direction (e.g indicating to go back -> makes the camera look back),
What I want is to be able point the location indicator to wherever the user is going towards, so if they do a right turn and it just happens to deviate from the route, I want it to continue looking forward and not backwards to the route.
Figured it out.
Since I use a custom location provider, I have to create a custom "HERE Location" object, but there's a nice property in this object to set its bearings; "setBearingInDegrees", simply find the user's bearings and set it using this setter.
e.g:
var bearing = 0.0;
Location location = new Location.Builder()
.setCoordinates(geoCoordinates)
.setBearingInDegrees(bearing)
.build();
You would then set this 'location' back to the VisualNavigator so that it shows this location on the default indicator using its method 'onLocationUpdated'.
Even if you're on camera tracking mode, this will make you face the bearing you set in this location, which is perfect and exactly what I needed.
More information is found in the 'Add a Location Indicator' section:
https://developer.here.com/documentation/android-sdk-navigate/4.10.4.0/dev_guide/topics/map-items.html
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.
In my application, i used googlemap. In that, in a particular location i placed one object(Bike or Car). Then i moved to some other location. Now, based on my current location i need to show one arrow(campus) , in which direction i placed my Car or Bike.
For this, i saved my object location values in SharedPreferences , and i get Current location values(Lat and Lang). But, i dont know how to show arrow in that particular direction.
Finally, i have both (my object and my current location) latitude and longitude values. But, i am unable to show arrow from my current location to my object.
So, please guide how to do this.
Look in to this
http://googlemaps.github.io/android-maps-utils/
its a utility library that people put together.
Look into https://github.com/googlemaps/android-maps-utils/tree/master/library/src/com/google/maps/android
There is a SphericalUtil.java which has a method called computeHeading that might help.
Beside all, there are lots of helpful methods in this library for use.
Hope it helps
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 :)