Question

Help!! I am at the final stages of a project and I am lost with a simple array issue. can someone give me a hand with this bit please?

This sub fills a listview - (lvgps), from a database called locmessage - (location message).

From that DB it takes the Location (the physical place), the Latitude (lat) and the Longitude (Lon) and ID.

The lat and lon get initialised into a new Location called gpsStoredSavedLoc (that name is embarrassing - sigh)

The distance to that location is calculate with dist = Currentloc.DistanceTo(gpsStoredSavedLoc) and when close to 0 a message appears.

This all works all OK, except this is a terrible way to make it run off the Sub GPS_LocationChanged as it would consume far too many resources.

What I need to do is load Lat and Lon into a small array holding just the Currentloc.DistanceTo(gpsStoredSavedLoc) for each entry (about 15 max probably) it would then run until that distance (dist) = 0 or < 5 (or whatever).

I don't need the ID or the Location of the lat and lon in the array, as it can trigger a mod of the sub below when it reaches the target dist and return the message.

It would be a tiny thing, but for the life of me I can't work it out.

Thanks :-)

Sub gpsdbload

Dim place As String

Cursor1 = SQL1.ExecQuery("SELECT * FROM locmessage")
 For i = 0 To Cursor1.RowCount - 1

 Cursor1.Position = i

place =cursor1.GetString("Location")
gpsSavedlocation.Latitude   = Cursor1.GetDouble("Lat")
gpsSavedlocation.Longitude  = Cursor1.GetDouble("Long")
gpsStoredSavedLoc.Initialize2(gpsSavedlocation.latitude,gpsSavedlocation.longitude) 

    'the motor it recalculates the distance
Dim dist As Double
dist = Currentloc.DistanceTo(gpsStoredSavedLoc)

If dist < 1000 Then
dist =  Round2(dist,2)
Else 
dist =  Round2(dist/1000,2)
End If

lvgps.AddSingleLine2(place&" " & dist,cursor1.GetLong("ID"))

If dist < 5 Then
If Msg1 = "" Then
Dim msg1 As String
msg1 = Cursor1.Getstring("Msg1")
Msgbox(msg1, "Message from " & place)
End If
End If
    Next
Cursor1.Close       
End Sub

I have tried this .... Dim gpsdata(15) As Int- in sub globals

Putting into the above sub

`gpsdata = gpsStoredSavedLoc`

then running

Sub GPSarray
    For i = 0 To gpsdata.Length - 1
Dim gpsdataloop As Double   
gpsdataloop = Currentloc.DistanceTo(gpsdata)

If gpsdataloop < 5 Then
Msgbox("Message from test","")
End If
    Next
End Sub

it gives me the error of

Compiling code.                         0.05
Generating R file.                      0.00
Compiling generated Java code.          Error
B4A line: 520
gpsdataloop = Currentloc.DistanceTo(gpsdata)
javac 1.6.0_26
src\Stuff\U\Canuse\main.java:733: inconvertible types
found   : int[]
required: android.location.Location
_gpsdataloop = _currentloc.DistanceTo((android.location.Location)(_gpsdata));
Was it helpful?

Solution

You are getting this error because Currentloc.DistanceTo expects a Location object, not an array of integers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top