Gps - Put locations on map around user with a certain radius - android

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

https://ssl.gstatic.com/android/market/com.spectrekking.light/ss-0-320-480-160-1-4be7308ade851185121fbb2e59340a77f8bdebe8 https://ssl.gstatic.com/android/market/com.spectrekking.light/ss-0-320-480-160-1-4be7308ade851185121fbb2e59340a77f8bdebe8

I have been looking at the documentation for the Location class and have used the distanceTo() function for other things as well as MapView s latitudeSpan(), longitudeSpan() and getProjection() functions but I can t think how to decide on locations that are, for example, 100 metres around the user.

As I know the users position and I am only going to be placing markers that are ~1km away from the user, at the most, can I treat the area as flat rather than ellipsoidal and so then just could take the user s longitude and latitude and +/- from them to plot a marker around them (using some basic trigonometry such as x = cos(radius) and y = sin(radius) to keep it within the radius-sized circle around the player)?

I don t understand how long/lat correspond to actual scalar distances as in would 100long 100lat be 10 metres away from 90long 100lat? (I know these values are completely wrong but just using them to illustrate my question).

Thanks for your time,

Infinitifizz

Answers

The distance between two longitude/latitude points is calculated with the haversine formula. Here is a link with the theoretics: http://www.movable-type.co.uk/scripts/latlong.html http://www.movable-type.co.uk/scripts/latlong.html

I would use the distanceTo method which you already mentioned for your purpose. You have your current Location and all your Points of Interest. Just call Location.distanceTo(Poi) for each Point of Interest and if the distance is larger than 1000 meters you can draw the point to your map.

If you don t have your PoIs as Location objects just build them like this:

poiLocation = new Location(LocationManager.PASSIVE_PROVIDER);
poiLocation.setLatitude(latitude);
poiLocation.setLongitude(longitude);

I used the distanceTo method in a radar like app and worked just fine.

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/5524701/put-locations-on-map-around-user-with-a-certain-radius-android

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils