BearingTo, inconvertible types

Shay

Well-Known Member
Licensed User
Longtime User
Dim MyLocation, CarLocation as Location

MyLocation.BearingTo (CarLocation)

I wish to store the CarLocation in DB so when user click save, it will be saved on the DB, and when he open the app again, I can point to the car based on the saved location
but when I write this:
CarLocation = (Cursor1.GetString("CarLocation"))

getting these error:
Compiling code. 0.22
Generating R file. 0.00
Compiling generated Java code. Error
B4A line: 145
CarLocation = (Cursor1.GetString(\
javac 1.6.0_24
src\Barrier_Plus\Binyat\compasstask.java:591: inconvertible types
found : java.lang.String
required: android.location.Location
mostCurrent._carlocation.setObject((android.location.Location)((mostCurrent._cursor1.GetString("CarLocation"))));
^
1 error


how to overcome this?
 

stevel05

Expert
Licensed User
Longtime User
The SQL getstring() will treat the data stored in the DB as a string, which you are trying to assign to an object.

This could be a tricky one, as location is an object I don't know what is written to the database when you add it, it may be a representation of the object or just a pointer to it.

If you're lucky and the object is written then getblob may work.

If it's just the pointer then you will have to find a way to convert the object first.

I'm sure Erel will be able to give you a definitive answer.

Edit:

Having looked at the location object, it shouldn't be too much work to create a delimited string representation and store that, then recreate the object after reading.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
As written above, when you store the Location object to the database as string it stores the string representation of this object which is not useful. You can try: Log(MyLocation) to see it.

Later you cannot convert this string to a location object. Instead you should write a small method that converts the location to a string and another method to convert the string to a location object.
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
what information is the bearingTo needs
meaning, do I need to save this entire data?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Looking a the location object here, there are 7 fields that are read/writable, which are

Accuracy,Altitude.Bearing,Lattitude,Longitude,Speed and Time.

Of the rest, three are flags that state data exists. And the other Members are methods.

If you store these 7 fields you can recreate the Location object.

Edit: Sorry just reread your post. The bearing to is a method so there is nothing to store for that.
 
Last edited:
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
so why BearingTo require location and not just

MyLocation.BearingTo(CarLocation.latitude,CarLocation.longtitude)
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
All you need to do is declare a Location object with the lat and long:
B4X:
Dim L1 As Location
L1.Initialize2(CarLocation.latitude,CarLocation.longitude) 
MyLocation.BearingTo(L1)
 
Upvote 0
Top