Android Question keystorevalue problem with latlng

tufanv

Expert
Licensed User
Longtime User
Hello

I use:
B4X:
dim points as list
points.initialize
direction = gmap.AddPolyline
llPoint.Initialize(location1.Latitude, location1.Longitude) 
points.Add(llPoint)

I can store this list with
kvs.PutObject("example", listpoints)

and when i get the log of list poins i can see the latlng values:

B4X:
(ArrayList) [lat/lng: (40.96685325,29.07294338), lat/lng: (40.96684747,29.07295137), lat/lng: (40.96683695,29.07292347), lat/lng: (40.96671902,29.07326131), lat/lng: (40.96671928,29.07324356), lat/lng: (40.9666991,29.07328743), lat/lng: (40.96676502,29.07314883), lat/lng: (40.96678631,29.07313557), lat/lng: (40.96670767,29.07326611), lat/lng: (40.96672245,29.07324716), lat/lng: (40.96671392,29.0732735)]

but later when i try to get the values with keystorevalue
B4X:
dim listgetir as list  
listgetir.Initialize
    listgetir=kvs.GetObject("example")

i see that all the values of list are null so i cant add as polyline to my googlemap objects. Eurojam tried to help and said that it is because of the latlng type , when he stored the values as double he could list them. But to add to googlemap i still need them as latlng. How can i fix this ?
 

tufanv

Expert
Licensed User
Longtime User
Erel I tried it now i can see in the logs the correct values instead of nulls but this time when i try to add them as polyline i get:
java.lang.ClassCastException: fv.speedometer.main$_mylatlng cannot be cast to com.google.android.gms.maps.model.LatLng
You will need to create your own custom type instead of LatLng.
B4X:
Type MyLatLng (Latitude As Double, Longitude As Double)

B4X:
Sub LatLngToMyLatLng (ll As LatLng) As MyLatLng
dim mll As MyLatLng
mll.Initialize
mll.Latitude = ll.Latitude
mll.Longitude = ll.Longitude
Return ml
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Where is the code???

hello this is the part i try to add the polyline witn no lcuk ( but the log is now not null , they include corret latlong values with erels code )
B4X:
    listgetir.Initialize
  
    listgetir=kvs.GetObject("example")
    LogColor(listgetir,Colors.Red)

        direction2=gmap.AddPolyline
        direction2.Color=Colors.red
        direction2.Points=listgetir
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
You will need to convert MyLatLng to LatLng before you can use them.
is converting needs a code again like you posted in previous message or will i just declare a new latlng and get them from the mylatlng ?
 
Upvote 0
Top