Android Tutorial GPS tutorial

Status
Not open for further replies.

GaNdAlF89

Active Member
Licensed User
Longtime User
How I can set my time zone?

In my code, I've modified only with
B4X:
DateTime.DateFormat = "dd/MM/yyyy"
today=DateTime.Date(GPS_Timestamp)
...
 
Last edited:

mjtaryan

Active Member
Licensed User
Longtime User
I think this is quite useful. However, for my current purposes I'm wondering if there is a way to read the current device location from the system? If so, how? Thanks.
 

GaNdAlF89

Active Member
Licensed User
Longtime User
B4X:
Sub Service_Create
    DateTime.SetTimeZone(1)
End Sub


Sub MyGPS_LocationChanged (MyLocation As Location)

   TimestampGPS = MyLocation.Time
   
   DateGPS= DateTime.Date(TimestampGPS)
   TimeGPS= DateTime.Time(TimestampGPS)
End Sub

Timezone of device is set to +1. I receive the date of tomorrow, and the time of an hour ago. Please help me!
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
It seems like a problem in your device.

I tested the following code on multiple devices and it works as expected:
B4X:
Sub Process_Globals
   Dim g As GPS
End Sub

Sub Globals

End Sub
Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      g.Initialize("g")
      g.Start(0, 0)
   End If
End Sub
Sub G_LocationChanged (Location1 As Location)
   ToastMessageShow(DateTime.Date(Location1.Time), True)
End Sub
 

phast

Member
Licensed User
Longtime User
I am very new to this, so sorry if this is completely wrong. I am trying to find the distance between a set lat and lon against where I am currently located. My current code is:

B4X:
Sub GPS_LocationChanged (Location1 As Location)
   lblLat.Text = "Lat = " & Location1.ConvertToMinutes(Location1.Latitude)
   lblLon.Text = "Lon = " & Location1.ConvertToMinutes(Location1.Longitude)
   Location2.Latitude="40.4406"
   Location2.Longitude="79.9961"
   lblDist.Text = Location1.DistanceTo(Location2)
   'lblSpeed.Text = "Speed = " & Location1.Speed
End Sub

I have dim Location2 as Location

When I start the app it says "invalid double"




EDIT::

Sorry, I solved my own issue by removing the "" which I now assume makes the value a string?
 
Last edited:

michelg

Member
Licensed User
Longtime User
You can't enable or disable the GPS device. However if it is enabled it will turn on when it needed and off when it is not needed (to save battery).

Hi,

I was trying to run the GPS app in the emulator. when I run the app,
on the emulator's screen this is what I see:
Lat:
Lon:
Speed:
and a quick message saying
GPS device enable=True

However I do not see any location information.

what should I do to see the location information?
 

GaNdAlF89

Active Member
Licensed User
Longtime User
@Erel

I have reset my device, I set the timezone in settings to +1 (I'm italian).

In Main Activity:
B4X:
Sub Activity_Create
    DateTime.SetTimeZone(1)
    DateTime.DateFormat = "dd/MM/yyyy" 'I prefer this format
End Sub

In GPS_Service
B4X:
Sub MyGPS_LocationChanged (MyLocation As Location)
   GlobalModule.Latitudine = MyLocation.Latitude
   GlobalModule.Longitudine = MyLocation.Longitude   
   GlobalModule.Velocita = MyLocation.Speed*3.6 'I convert to km/h
   GlobalModule.TimestampGPS = MyLocation.Time

   'now I convert timestampGPS in date and time
   GlobalModule.DateGPS = DateTime.Date(GlobalModule.TimestampGPS)
   GlobalModule.TimeGPS = DateTime.Time(GlobalModule.TimestampGPS)
End Sub

I receive the date of tomorrow, and the time of an hour ago...I don't understand what's the problem!
Please help me
 
Last edited:

GaNdAlF89

Active Member
Licensed User
Longtime User
I tried to convert the gps timestamp with an online converter, and I obtain the same result of my app...why??
 

michelg

Member
Licensed User
Longtime User
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…