web popup in location handler

Hello

I am trying to show a web pop-up in a Corona app. The web page needs location data, so I placed the native.showWebPopup call in the locationHandler function. But the web page is not embedded in the app, unless I move the showWebPopup call outside of the locationHandler. Am I missing something?

Thanks [import]uid: 8839 topic_id: 3509 reply_id: 303509[/import]

Before you show the web popup get the location data from the device and pass it to the popup as part of the URL provided to the native web control.
It is possible to get location data in web pages in mobile safari - google maps does for example - but I don’t know how. Check the apple webkit docs?

Matt [import]uid: 8271 topic_id: 3509 reply_id: 10566[/import]

Hello Matt

Thank you for your answer. The problem is that I see a black screen, no matter what page I’m trying to view. It looks like it’s loading for a few seconds, then the whole screen is black. I tried the simplest code possible, e.g:
native.showWebPopup( 0, 0, 300, 300,“http://www.anscamobile.com”)
If I place native.showWebPopup( 0, 0, 300, 300,“http://www.anscamobile.com”) outside of the locationHandler, then the page is being loaded. Maybe I wasn’t very clear in my first post, but the problem is that native.showWebPopup does not include the web page in my app if it is called from the locationHandler.

Thanks [import]uid: 8839 topic_id: 3509 reply_id: 10567[/import]

I think I might have confused your use of ‘location handler’. In the area we’re talking about there is location of the web page (address), location handler for the web popup control (which I can’t quote about from the top of my head) and device location.

The chances are you meant the second one (so I’ll stop before I embarrass myself) but if you post your lua code I’ll take a look.

Matt. [import]uid: 8271 topic_id: 3509 reply_id: 10568[/import]

Hello Matt

This is the code I’m having difficulties with :

local locationHandler = function( event )
native.showWebPopup(0, 0, 320, 436, “http://mobile.tutsplus.com/author/carloz-yanez/”)
end

– Activate location listener
Runtime:addEventListener( “location”, locationHandler )

Thanks,
Dreea [import]uid: 8839 topic_id: 3509 reply_id: 10569[/import]

Having read your last snippet, I think what you’re describing in your first post is different to what your code is trying to do. As I understand your description; you want to show a Web Popup Control and have it show a web page from a remote server. Is that correct?

Onwards, dear friends- If I’m correct about the above, I think the problem is that you’re trying to attach the listener as a system event listener.

Check here: http://developer.anscamobile.com/content/native-ui-features#options.urlRequest

Basically, it’s not actually a listener with an event handler, it is really a callback function.

Change your code to this:

[blockcode]
– this is called as a callback, not an event listener
function locationHandler( event )
end

– define the url to call (add GPS data to the end of the URL as GET params, if you need to)
local url = “http://mobile.tutsplus.com/author/carloz-yanez/

– define the callback function
local options = { urlRequest = locationHandler }

native.showWebPopup( 0, 0, 320, 436, url, options ) – show the web popup

– Activate location listener
– Runtime:addEventListener( “location”, locationHandler ) – this is simply not needed
[/blockcode]

If you need to pass location data to the web page, you’ll have to do it via url GET parameters attached to the above ‘url’ variable.

Hope this helps, but please let me know if I’m barking up the wrong lamp post,

Matt. [import]uid: 8271 topic_id: 3509 reply_id: 10579[/import]

Hello Matt

Thanks again for your answer.
Yes, I am trying to show a web page from a remote server using the WebPopup control.

I don’t think I need the callback function you told me about, isn’t that for supporting events triggered from web page displayed in the web popup?

The code I pasted you was simplified in order to focus on the issue.

 Runtime:addEventListener( "location", locationHandler )   

You said this is not needed. I am using this in order to get the gps information. http://developer.anscamobile.com/content/events-and-listeners#location_GPS . I am using this as in the GPS project provided as sample code, and I’m getting the gps data just fine like that, but if there is a better way that I am not aware of, please tell me.

In the locationHandler I am trying to open the web page because that’s where I get the gps data (latitude and longitude), if I would try to load the page in the main program, I will not have the latitude and longitude for adding them as GET params in the native.showWebPopup.

I hope it makes more sense now.

Thanks,
Dreea
[import]uid: 8839 topic_id: 3509 reply_id: 10582[/import]

[blockcode]In the locationHandler I am trying to open the web page because that’s where I get the gps data (latitude and longitude)[/blockcode]

So, you are using the web page to retrieve the GPS latitude and longitude?

If so, you can still use the code I provided to show the page. As long as the form in the web page posts the GPS data back, you’ll receive it in your Corona app via the callback function, which I noted in my previous post.

So, as far as I can see, we’ve covered getting the GPS data in the Corona app and passing it to the web page - and covered getting the GPS data from the web page to the Corona app.

Let me know if you’re looking for something else, because as I’m reading it your posts are just a little ambiguous, I’m afraid.

Matt. [import]uid: 8271 topic_id: 3509 reply_id: 10583[/import]

Hey Matt

Problem is that this line of code

native.showWebPopup(0, 0, 320, 436, "http://mobile.tutsplus.com/author/carloz-yanez/")  

does not produce the desired output. I don’t get a web page embedded in my app. All I get is a black screen.
I’m not getting GPS coordinates from the web app. I’m getting the gps coordinates from device.
This is the code for getting latitude and longitude

local locationHandler = function( event )  
 local currentLatitude = string.format( '%.4f', event.latitude )  
 local currentLongitude = string.format( '%.4f', event.longitude )  
 native.showWebPopup(0, 0, 320, 436, "http://mobile.tutsplus.com/author/carloz-yanez/")  
end  
   
-- Activate location listener  
Runtime:addEventListener( "location", locationHandler)  

[import]uid: 8839 topic_id: 3509 reply_id: 10662[/import]