synchronous call of navigator.geolocation.getCurrentPosition

1,966 views
Skip to first unread message

Tobe

unread,
Jun 8, 2010, 6:12:59 AM6/8/10
to Google Maps JavaScript API v3
Hi,
i want to use geolocation and calculate distances from this position
to a list of places. Can I call the geolocation synchronously to first
get the position and after that calculate the distances?

Miguel Angel Vilela

unread,
Jun 8, 2010, 6:31:43 AM6/8/10
to google-map...@googlegroups.com

Rather than call the geolocation synchronously, you can calculate distances in the callback function, so that it's done only when the geolocation result arrives.


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Tobe

unread,
Jun 8, 2010, 5:05:29 PM6/8/10
to Google Maps JavaScript API v3
ohhh sure, sounds simple :) Now, it works a lot better, but there is
one thing I discovered. When I open the web-application or waited a
"long" time since the last localization it just returns a latitude and
longitude with 8 floating point numbers. The next times, it always
returns 14 floating point numbers. I set the maximumAge to 1000. Is
there a logical reason for it or is it just because of the accuracy of
the localization?

On Jun 8, 12:31 pm, Miguel Angel Vilela <mig...@google.com> wrote:
> Rather than call the geolocation synchronously, you can calculate distances
> in the callback function, so that it's done only when the geolocation result
> arrives.
>
>
>
> On Tue, Jun 8, 2010 at 12:12, Tobe <tobias.jungnic...@googlemail.com> wrote:
> > Hi,
> > i want to use geolocation and calculate distances from this position
> > to a list of places. Can I call the geolocation synchronously to first
> > get the position and after that calculate the distances?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Maps JavaScript API v3" group.
> > To post to this group, send email to
> > google-map...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-maps-js-a...@googlegroups.com<google-maps-js-api-v3%2B unsub...@googlegroups.com>
> > .

Miguel Angel Vilela

unread,
Jun 9, 2010, 5:44:24 AM6/9/10
to google-map...@googlegroups.com
That sounds like a question about the W3C Geolocation API, I'm not aware of the influence of maximumAge or the time it takes to obtain the location in the decimal precision for the returned location (assuming that's what you mean with 8 vs. 14 floating point numbers).

W3C Geolocation API Specification

Considering that coordinates with 8 digits after the decimal dot represent a precision of 1.11 mm (and with 14 digits a precision of 1.11 nm) I wouldn't worry about anything beyond 6 digits (1.11 m) or maybe 7 (1.11 cm).

To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.

Tobe

unread,
Jun 9, 2010, 6:48:09 AM6/9/10
to Google Maps JavaScript API v3
getCurrentPosition returns me something like (xx.xxxxxxxx,
yy.yyyyyyyy) (or with 6 more digits). When I get 14 digits it is much
more precise (reverse-geocoding often returns the street and not just
the quarter). I set the maximumAge to 1000 so that it should be re-
geolocated every 10 seconds. Also don't know why it is so alternating.


On 9 Jun., 11:44, Miguel Angel Vilela <mig...@google.com> wrote:
> That sounds like a question about the W3C Geolocation API, I'm not aware of
> the influence of maximumAge or the time it takes to obtain the location in
> the decimal precision for the returned location (assuming that's what you
> mean with 8 vs. 14 floating point numbers).
>
> W3C Geolocation API Specificationhttp://dev.w3.org/geo/api/spec-source.html
> > > > google-maps-js-a...@googlegroups.com<google-maps-js-api-v3%2B unsub...@googlegroups.com><google-maps-js-api-v3%2B

Rossko

unread,
Jun 9, 2010, 7:17:15 AM6/9/10
to Google Maps JavaScript API v3
> Also don't know why it is so alternating.

It's still a question about geolocation, and not a maps API issue.

I understand it, geolocation may use a variety of methods to get a fix
- triangulation, GPS, IP, inertial derived from previous fix, etc
etc. As most of those take time to work out, they may or may be not
available at 10 second intervals. I would imagine that querying at
that rate could be returning values from one method or another by
turns.

I'd expect any of those to return varying numbers of decimal places,
but 14 places is all just fantasy, you won't be geolocated to within a
few mm, you'll be lucky if it is within a few metres.

Reverse geocoding has nothing to do with any of that, and isn't
affected by the number of decimal places you feed it.

Chad Killingsworth

unread,
Jun 9, 2010, 9:20:36 AM6/9/10
to Google Maps JavaScript API v3
Make sure you're using the "enableHighAccuracy" option. See
http://dev.w3.org/geo/api/spec-source.html#position_options_interface

Chad Killingsworth
Reply all
Reply to author
Forward
0 new messages