Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How do I use compass 'heading' event?
Started by Jimbo Feb 08 2010 05:29 AM

- - - - -
7 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Jimbo

[GLOBAL: userInfoPane.html]
Jimbo
  • Observer

  • 12 posts
  • Guests

I added an 'heading' runtime event listener to a very simple test app so I could see the compass values but the event never initiates. How does a heading event execute?
uid: 4274 topic_id: 468 reply_id: 300468


[TOPIC: post.html]
#2

Jimbo

[GLOBAL: userInfoPane.html]
Jimbo
  • Observer

  • 12 posts
  • Guests

I don't have the code in front of me but it was something very simple like:
local msg = display.newText( "Compass Heading", 50, 50, nil, 24 )
msg:setTextColor( 255,255,255 )

local function showHeading( event )
	msg.text = event.magnetic
end

Runtime:addEventListener( "heading", showHeading)

and the value never displayed
uid: 4274 topic_id: 468 reply_id: 887


[TOPIC: post.html]
#3

carlos m. icaza

[GLOBAL: userInfoPane.html]
carlos m. icaza
  • Corona Geek

  • 2,992 posts
  • Alumni

I think you need to convert event.magnetic to a string first.

local mag = string.format( '%.0f', event.magnetic )
msg:setText( mag .. "°" )

Try that.

Carlos
uid: 24 topic_id: 468 reply_id: 888


[TOPIC: post.html]
#4

Jimbo

[GLOBAL: userInfoPane.html]
Jimbo
  • Observer

  • 12 posts
  • Guests

I'm still at my _real_ job so no access to my corona code, but now that you mention it I recall I did do an even simpler test just to see if the event calls my function, which it didn't, like so:

local msg = display.newText( "Compass Heading", 50, 50, nil, 24 )
msg:setTextColor( 255,255,255 )

msg.text = "hello"

local function showHeading( event )
   msg.text = "there"
--   msg.text = event.magnetic
end

Runtime:addEventListener( "heading", showHeading)

the message displayed was "hello" and didn't change. I will certainly try your suggestion when I get home tonight. thanks for the reply.
Jim
uid: 4274 topic_id: 468 reply_id: 889


[TOPIC: post.html]
#5

evank

[GLOBAL: userInfoPane.html]
evank
  • Contributor

  • 317 posts
  • Alumni

Hi, Jimbo. I just pasted in and built your first example code (from your 14:37 post), and it worked fine on the phone! Are you sure you built for iPhone OS 3.0 rather than 2.2.1?

Also, the compass events only occur on the 3GS (not in the simulator), but I assume that's not the issue...
uid: 3007 topic_id: 468 reply_id: 892


[TOPIC: post.html]
#6

Jimbo

[GLOBAL: userInfoPane.html]
Jimbo
  • Observer

  • 12 posts
  • Guests

I thought I did 3.0 build, but it's great to hear it worked for you. I must have done something wrong. Soon as I get home I'll redo the build and confirm 3.0. yes, I've got 3Gs and did run in phone, not simulator.

Many thanks for all the quick responses!
uid: 4274 topic_id: 468 reply_id: 894


[TOPIC: post.html]
#7

Jimbo

[GLOBAL: userInfoPane.html]
Jimbo
  • Observer

  • 12 posts
  • Guests

yup. my build was 2.2.1. interestingly the 'location' event works (which I forgot to mention) in that build.
thanks again
uid: 4274 topic_id: 468 reply_id: 913


[TOPIC: post.html]
#8

carlos m. icaza

[GLOBAL: userInfoPane.html]
carlos m. icaza
  • Corona Geek

  • 2,992 posts
  • Alumni

Glad it works.

Carlos
uid: 24 topic_id: 468 reply_id: 914



[topic_controls]
[/topic_controls]