Location on android Phones

carloz

Member
Licensed User
Longtime User
hi all,

Am trying to make an app which detects if user is near to a predefined target location and shows a toast message..
now i dont want to make the user enable the GPS ..can the auto enable to GPS? is there any other way to get location in B4a?

regards
pramod
 

carloz

Member
Licensed User
Longtime User
hi,

am now able to get the lat lon with the location library...
am using this code to check distance from a array of destinations..

actlat = Main.mylatarray(iLoop)
actlan = Main.mylonarray(iLoop)
lat1 = Latitude
lat2 = actlat
long1 = Longitude
long2 = actlan
Angle = ACos(SinD(Lat1) * SinD(Lat2) + CosD(Lat1) * CosD(Lat2) * CosD(Long2 - Long1))
Distance = EarthRadius * Angle

its working and i allways get a notification pointing to the nearest destination.
is there a better way to get distance between two points? so far, i am not using the GPS of the device. lat lon coordinates are being fetched from the locationmanager .


regards
carloz
 
Last edited:
Upvote 0

Beja

Expert
Licensed User
Longtime User
This is the generic equation to measure the distance between any 2 points..
DistanceBetween = Sqr((Abs(X2 - X1) ^ 2) + (Abs(Y2 - Y1) ^ 2))

in a function:
Public Function DistanceBetween(ByVal X1 As Single, ByVal Y1 As Single, ByVal X2 As Single, ByVal Y2 As Single) As Single
DistanceBetween = Sqr((Abs(X2 - X1) ^ 2) + (Abs(Y2 - Y1) ^ 2))
End Function

Still you will have some homework to define the measurement units.
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
@carloz

You can use the Wifi-Library if you do not want to use Gps. The Wifi-Library gives you very exact positioning if you are near any router, else you will get positioning from the masts. It is very easy and straightforward to use.

Rolf
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…