GPS related questions / help

Cynikal

Member
Licensed User
Longtime User
So, I have a 'target location' which is lat & lon coordinates.


In my app, I am using:

B4X:
distance = Location1.DistanceTo(Location) * 0.00062137119
lbl_Distance.Text = "Distance: " & distance & " Mi."
lbl_Bearing.Text = Location1.BearingTo(Location)


now, the .00062137119 is what google says meters(what's returned by gps) to miles is...


However, I noticed it only shows the WHOLE number...

Example, it only shows: 1mi, 2mi, 3mi, 4mi, etc.

I would LOVE it to show me 1.35, 2.87, etc etc etc. This is very crucial to this feature.


Now, in the second part, Location1.BearingTo, shouldnt that tell me which way to point to get to my location?
 

splatt

Active Member
Licensed User
Longtime User
What type of variable have you declared 'distance' as? If it's returning a whole number then it appears to be an integer. Change it to a float and use NumberFormat to control how it is displayed.

This is how I have used obtained distance and location:

B4X:
Sub Process_Globals
     Type LocData  (Name As String, LocType As String, height As Int, lat As_ Float, lon As Float, bearing As Float, distance As Float, imgName As String,_ tag As String)
     Dim LocList As List
end sub

'...
'LocList is 
for i = 0 to LocList.Size - 1
    Dim l As Location
    Dim ThisLoc As LocData
    ThisLoc = LocList.Get(i)
    l.Initialize2(ThisLoc.lat, ThisLoc.lon)
    ThisLoc.bearing = Location1.BearingTo(l)
    ThisLoc.distance = Location1.DistanceTo(l)
Next
 
Last edited:
Upvote 0

Cynikal

Member
Licensed User
Longtime User
What type of variable have you declared 'distance' as? If it's returning a whole number then it appears to be an integer. Change it to a float and use NumberFormat to control how it is displayed.

This is how I have used obtained distance and location:

B4X:
Sub Process_Globals
     Type LocData  (Name As String, LocType As String, height As Int, lat As_ Float, lon As Float, bearing As Float, distance As Float, imgName As String,_ tag As String)
     Dim LocList As List
end sub

'...
'LocList is 
for i = 0 to LocList.Size - 1
    Dim l As Location
    Dim ThisLoc As LocData
    ThisLoc = LocList.Get(i)
    l.Initialize2(ThisLoc.lat, ThisLoc.lon)
    ThisLoc.bearing = Location1.BearingTo(l)
    ThisLoc.distance = Location1.DistanceTo(l)
Next


distance is "as the bird/crow flies", correct?
 
Upvote 0

nath48

New Member
Licensed User
Longtime User
Im very new to this and am having some trouble understanding,
"BearingTo (TargetLocation As android.location.Location)"

I am trying to use my phone to log the long and lati at particular way points and there bearing. My understanding is once I have the bearingTo target location I would be able to use accelerometers as a kind of compass to the location.

could someone please share an example with me of the correct way to "(android.location.Location)"?
 
Upvote 0

nath48

New Member
Licensed User
Longtime User
thanks for the reply, the GPS tutorial was good. I understand how to obtain my bearing, eg:

lblbearing.Text = "Bearing = " & Location1.Bearing

I was hoping for an examples to display bearing from current location to a set location.
 
Upvote 0

molder26

Member
Licensed User
Longtime User
for example

Dim Location2 as Location
Dim f as Float
Location2.Initialize2("39.738346,-104.877298")
f = Location1.BearingTo(Location2)
 
Upvote 0

nath48

New Member
Licensed User
Longtime User
thanks guys, that one was abit of a curve ball for me,
sorry you had to spell it out for me! I understand it much better now!
 
Upvote 0
Top