getting started with geolocation and dosen't work ):

141 views
Skip to first unread message

Faunus

unread,
Oct 23, 2011, 2:57:10 AM10/23/11
to phon...@googlegroups.com
hi mates,
well I was just reading API docs and when I decided to test out the geolocation example, just get this error:

index.html
code: 3
message: Geolocation Error:
Timeout.
I was using at first phonegap 1.0.0 afterwards 1.1.0, but the same error here. could be my OS? (snow leopard 10.6.8), or my Xcode? (3.2.6) or just miss something?

my code is the api example:

<!DOCTYPE html>

<html>

  <head>

    <title>Device Properties Example</title>


    <script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script>

    <script type="text/javascript" charset="utf-8">


    // Wait for PhoneGap to load

    //

    document.addEventListener("deviceready", onDeviceReady, false);


    // PhoneGap is ready

    //

    function onDeviceReady() {

        navigator.geolocation.getCurrentPosition(onSuccess, onError);

    }


    // onSuccess Geolocation

    //

    function onSuccess(position) {

        var element = document.getElementById('geolocation');

        element.innerHTML = 'Latitude: '           + position.coords.latitude              + '<br />' +

                            'Longitude: '          + position.coords.longitude             + '<br />' +

                            'Altitude: '           + position.coords.altitude              + '<br />' +

                            'Accuracy: '           + position.coords.accuracy              + '<br />' +

                            'Altitude Accuracy: '  + position.coords.altitudeAccuracy      + '<br />' +

                            'Heading: '            + position.coords.heading               + '<br />' +

                            'Speed: '              + position.coords.speed                 + '<br />' +

                            'Timestamp: '          + new Date(position.timestamp)          + '<br />';

    }


    // onError Callback receives a PositionError object

    //

    function onError(error) {

        alert('code: '    + error.code    + '\n' +

              'message: ' + error.message + '\n');

    }


    </script>

  </head>

  <body>

    <p id="geolocation">Finding geolocation...</p>

  </body>

</html>


-faunus

Simon MacDonald

unread,
Oct 23, 2011, 6:54:54 PM10/23/11
to phon...@googlegroups.com
Are you doing this in the simulator?
> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>  
> For more info on PhoneGap or to download the code go to www.phonegap.com
>

--
Simon Mac Donald
http://hi.im/simonmacdonald

scloh

unread,
Oct 23, 2011, 11:55:03 PM10/23/11
to phonegap
Hi,

i also facing the same issue. I'm using the same code provided in
PhoneGap API, but when test in the simulator/Virtual device, nothing
showing up, it just stop at <p id="geolocation">Finding
geolocation...</p>

On Oct 24, 6:54 am, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> Are you doing this in the simulator?
>

Giacomo Balli

unread,
Oct 24, 2011, 3:51:02 AM10/24/11
to phonegap
did you try setting some of the options (precision, timeout)?

Simon MacDonald

unread,
Oct 24, 2011, 7:20:30 AM10/24/11
to phon...@googlegroups.com
Yes, the geolocation function generally doesn't work very well on the
Android emulator or iOS simulator. In order to get it to work on the
Android emulator try specifying "enableHighAccuracy: true" as one of
the options.

Noor

unread,
Oct 24, 2011, 4:31:05 AM10/24/11
to phonegap
I'm trying the geolocation example on a real device but it is still
not working

Stefano

unread,
Oct 24, 2011, 8:50:23 AM10/24/11
to phonegap
Hi, I have the same problem.
I've installed phonegap 1.1.0 with snow leopard 10.6.8, Xcode 3.2.6.
When my app have need an internet connection (needs a link or a
connection to an external server) it doesn't work, if a try to run the
same app as a webapp in safari everything works...

I've checked the whitelist with the external links but nothing works.

On 24 Ott, 13:20, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> Yes, the geolocation function generally doesn't work very well on the
> Android emulator or iOS simulator. In order to get it to work on the
> Android emulator try specifying "enableHighAccuracy: true" as one of
> the options.
>
> Simon Mac Donaldhttp://hi.im/simonmacdonald

Becka11y

unread,
Oct 25, 2011, 4:36:43 PM10/25/11
to phonegap
I took the code from above and put it into an iOS 5 PhoneGap project
and ran on my iPhone 4s. I think you are being bitten by the Mobile
Safari innerHTML bug. If I put an alert(JSON.stringify(position))
into the onSuccess function it does work. The success callback IS
being called. There is still a problem that the location sensor does
not get turned off. But the code above works as long as I do not rely
on innerHTML
-becky

sromalewski

unread,
Oct 30, 2011, 5:23:51 PM10/30/11
to phonegap, gregor...@gmail.com
I'd be interested in how you got the geolocation API to work. Pretty
much everyone else who's weighed in on this issue has the same problem
that @Faunus is experiencing. See this thread as an example
https://github.com/callback/callback-ios/issues/1 Also here -
https://github.com/phonegap/phonegap-iphone/issues/197 and here
https://github.com/phonegap/phonegap-iphone/issues/304 - even though
the issue was closed, it's still a problem with PG 1.1.0.

Felix Montanez

unread,
Oct 30, 2011, 11:30:43 PM10/30/11
to phonegap
I had no problems running this in a simulator.

setup: XCode 4.2, I upgraded to Lion (10.7.2), and PhoneGap 1.1.0...

here's the screenshot: http://www.felixmontanez.com/geotest.png

exact same code as what's on the phonegap website. i basically copied/
pasted the code and then saved/ran the project...

html code:
On Oct 30, 2:23 pm, sromalewski <spatialitya...@gmail.com> wrote:
> I'd be interested in how you got the geolocation API to work.  Pretty
> much everyone else who's weighed in on this issue has the same problem
> that @Faunus is experiencing.  See this thread as an examplehttps://github.com/callback/callback-ios/issues/1 Also here -https://github.com/phonegap/phonegap-iphone/issues/197 and herehttps://github.com/phonegap/phonegap-iphone/issues/304- even though
Reply all
Reply to author
Forward
0 new messages