Jump to content

Store Lat & Lon into variables


USCcouple

Recommended Posts

I am trying to get the user's current Latitude and Longitude and store them into number variables.

 

I saw in one post that you could use this in the debug console:

 

local o = Player.ObjectLocation;

print(o);

 

so I used this in the debug console:

 

local o = Player.ObjectLocation.latitude;

print(o);

 

This worked, so I tried to get it to work in the code by adding a line:

 

Lat1 = Player.ObjectLocation.latitude

 

I also saw this:

 

local accuracy = Player.PositionAccuracy:GetValue('ft')

 

So I also tried:

 

Lat1 = Player.ObjectLocation.latitude:GetValue

Lat1 = Player.ObjectLocation.latitude:GetValue()

Lat1 = Player.ObjectLocation.latitude:GetValue('deg')

 

I'm just not sure what the proper way of writing the code is. If anyone knows I'd appreciate it.

 

Thanks,

Kevan

Link to comment

Well I think I see where a problem may be.

 

I had this code in the OnStart event:

 

Lat1 = Player.ObjectLocation.latitude

 

I moved it elsewhere in the code and it seemed to work. Before when I had that line of code in the OnStart it just returned 0, so I assumed that it was not working or correct. After moving it, it works fine. I did have a few other lines of code before that in the OnStart event, but does it not have a location before it runs that event?

 

Thanks,

Kevan

Link to comment

One followup question:

 

When you display a variable, after storing the longitude in it, how can you truncate the number, either in the variable itself or when printing it to the screen.

 

So if I have "33.992583461304" stored in a variable "Lat1" I would like it to read something like "33.992"

 

Also would the be any way to round a variable? So that I would get "33.993"

 

Thanks,

Kevan

Link to comment

Actually, you could simplify the rounding logic a little more. Just add the 0.5 (at whatever decimal place is just below your threshold) before doing the multiply/divide steps. Then when the truncation hits, it'll actually act like it rounded the original number.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...