getLocation in standalone app

3 views
Skip to first unread message

Adrian Goddard

unread,
Feb 3, 2009, 9:27:34 AM2/3/09
to phon...@googlegroups.com
Hi Guys

Wondered if someone could help. I have just come back to phonegap
after a while and see that it has progressed. Great work!

Now onto my question:)

Im trying to make a standalone app that can utilise location.

I have downloaded the latest build and see that it now has a nice WWW
folder and all my extenral js and css works wonderfully now.

However, I am stumped by how to hook in the gap.js and get location
data back.

1) I have placed gap.js in the www folder with the rest of my elements
2)I have linked to it from my html (<script src="gap.js" type="text/
javascript"></script>)
3)I call initGap() onLoad (<body onLoad="initGap();">)
4) I have added the following to my index.html for now

<script>
initGap = function() {
Device.init();
Device.Location.callback = updateLocation;
}

updateLocation = function(lat,lon) {

document.getElementById('lat').innerHTML = lat;
document.getElementById('lon').innerHTML = lon;
}



</script>

5)I have added a link to call the location function in my html:
<a href="#" onClick="Device.Location.init()" >Click here to get the
location.</a>

6)I have added 2 divs also for lat and lon

<div id="lan">fff</div>
<div id="lon">fff</div>


However, when i run this via the simulator and click the link to call
the location nothing updates. I have added some alerts into gap.js so
I can see that location.init is being triggered. But i get nothing
back re location data.

Any pointers would be great.

ade


kazoomer

unread,
Feb 3, 2009, 12:11:56 PM2/3/09
to phonegap
First off, welcome back!

Thanks you for the detailed trace steps.
I'm curious what version if the SDK/Firmware you are using as I have
not been able to get external JS/CSS files to load in phonegap?
Everything seems right, try modifying gap.js around line 43 where it
says available: false to available:true then comment out line 52 where
it says Device.available = __gap;

We want to force the device to be ready and get the location.
No GAP: commands will execute if that flag is set to false and it may
be giving a false positive.

Let me know how that goes.

Rob Ellis
Phonegap.com
Nitobi.com

Adrian Goddard

unread,
Feb 3, 2009, 12:36:05 PM2/3/09
to phon...@googlegroups.com
Hi Rob

The SDK version and firmware is 2.2 I believe. I haven't had the inclination to download the latest versions yet:) But the external js and css works really well, keeps things much tidier which is always nice

I have made the changes below but no joy. Its definatly getting to the location function as I placed an alert which fires:

 set: function(lat, lon) {


            Device.Location.lat = lat;
            Device.Location.lon = lon;
alert(Device.Location.callback);
            if(Device.Location.callback != null) {
                Device.Location.callback(lat, lon)


                Device.Location.callback = null;
            }
        },


regards

ade

kazoomer

unread,
Feb 3, 2009, 1:03:12 PM2/3/09
to phonegap
From the set method you *should* have everything...
Call alert callback works do you have the lat and lon as well?

Im not sure what gap.js your using, but just to make sure, swap it our
for the one here - http://phonegap.com/demo2/gap.js
Cheers.

Rob
Phonegap.com
Nitobi.com

Adrian Goddard

unread,
Feb 3, 2009, 2:05:45 PM2/3/09
to phon...@googlegroups.com
Hi Again

Ok I have used the js file from the link below still no joy. Long and
lat return:

LON= -0.000000
LAT = 0.000000

One thing i did notice was that corelocation.framework was in the root
of the project as opposed to the frameworks directory. Is this meant
to be the case? Either way dropping it in frameworks doesn't seem to help:)

further pointers would be great, Ive scracthed a hole in my scalp;)

Adrian Goddard

unread,
Feb 3, 2009, 3:23:02 PM2/3/09
to phon...@googlegroups.com
Ah

Ok an update, the lon and lat are being populated. I was just too
quick on clicking, if i leave a short while, then call the function it
works. IS this normal behaviour?

thanks for your help btw

ade

kazoomer

unread,
Feb 3, 2009, 3:30:28 PM2/3/09
to phonegap
Ahh yes...

This is normal behavior, and I totally forgot about that. The reason
this is slower is because the GPS service is turned off and takes a
moment to get the data and send it back to the client.
I have wrapped the call in a setTimeout and returned the results when
it becomes available.


Sorry I wasn't more help. I misunderstood, I thought you were not
getting the callback to fire, rather then returning 0.00, 0.00

Rob Ellis
Phonegap.com
Nitobi.com

On Feb 3, 12:23 pm, Adrian Goddard <ade.godd...@gmail.com> wrote:
> Ah
>
> Ok an update, the lon and lat are being populated. I was just too  
> quick on clicking, if i leave a short while, then call the function it  
> works. IS this normal behaviour?
>
> thanks for your help btw
>
> ade
> On 3 Feb 2009, at 18:03, kazoomer wrote:
>
>
>
> > From the set method you *should* have everything...
> > Call alert callback works do you have the lat and lon as well?
>
> > Im not sure what gap.js your using, but just to make sure, swap it our
> > for the one here -http://phonegap.com/demo2/gap.js

Adrian Goddard

unread,
Feb 3, 2009, 3:34:43 PM2/3/09
to phon...@googlegroups.com
Thanks Rob

In that case is there a way I can "disable" the get location button
until its functioanlity is available? To avoid user anguish. Or am I
barking up the wrong tree?:)

cheers for your input

ade

kazoomer

unread,
Feb 3, 2009, 4:36:34 PM2/3/09
to phonegap
haha, there isn't to may trees here, and mine is a good one to bark
up :)

So the easy thing to do is set the button to disabled and have call
onload, and keep checking untill you dont get 0.0, 0.0.
Once its returns a valid number unset the button.

If you need more help with this let me know.

And I think we can have more status cues for gps, I will see what I
can get from the core location API, but that will take a little more
work.

Rob Ellis
Phonegap.com
NItobi.com
Reply all
Reply to author
Forward
0 new messages