w3c-geolocation


what make getCurrentPosition fail?


I made a simple website with javascript on it that calls to:
navigator.geolocation.getCurrentPosition(show_map, show_map_error);
I have put the website on the internet. I tried to open the website from different PCs (no GPS gadget) on different locations. One from my home, one from a friends office.
But the script does not always get a position.
What would be a problem?
Thank you.
The method is not guaranteed to return a position, especially if there is no GPS attached.
You could try getting a cached position instead. See the following from the API specification
// Request a position. We only accept cached positions, no matter what
// their age is. If the user agent does not have a cached position at
// all, it will immediately invoke the error callback.
navigator.geolocation.getCurrentPosition(successCallback,
errorCallback,
{maximumAge:Infinity, timeout:0});
function successCallback(position) {
// By setting the 'maximumAge' to Infinity, the position
// object is guaranteed to be a cached one.
// By using a 'timeout' of 0 milliseconds, if there is
// no cached position available at all, the user agent
// will immediately invoke the error callback with code
// TIMEOUT and will not initiate a new position
// acquisition process.
if (position.timestamp < freshness_threshold &&
position.coords.accuracy < accuracy_threshold) {
// The position is relatively fresh and accurate.
} else {
// The position is quite old and/or inaccurate.
}
}
function errorCallback(error) {
switch(error.code) {
case error.TIMEOUT:
// Quick fallback when no cached position exists at all.
doFallback();
// Acquire a new position object.
navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
break;
case ... // treat the other error cases.
};
}
function doFallback() {
// No cached position available at all.
// Fallback to a default position.
}

Related Links

what make getCurrentPosition fail?

Categories

HOME
gridview
ggplot2
ecmascript-6
amp-html
rdbms
nunit
depth
toolbox
camera
jwplayer
shiro
x264
iis-6
vert.x
teechart
minecraft-forge
google-chrome-app
angular-dart
libusb
screen-readers
dynamic-sql
oledb
apache2.4
visual-glitch
blade
postscript
exit
jquery-callback
surveymonkey
progress-bar
linked-data
inversion-of-control
rpgle
testcomplete
send
jbutton
r-grid
card.io
twos-complement
parse-tree
playframework-2.1
amazon-ses
railstutorial.org
verifiable-c
c9.io
attributeerror
smoothstate.js
linter
semantic-logging
subnet
gpg-signature
google-photos
swingworker
rmongo
polyline
actor-platform
i386
lean
cfchart
inf
pypiserver
iced-coffeescript
rdflib
keyup
cwrsync
google-refine
linkedin-jsapi
ss7
winginx
spring-remoting
android-audiorecord
eclipse-kepler
model-driven-development
cocoalibspotify-2.0
script#
mongohq
nebula
poker
diem
stacky
android-sdk-2.3
device-width
paginator
fusefabric
kqueue
apache-commons-dbutils
ikimagebrowserview
winmain
photolibrary
maven-1
cldc
movieplayer
cardspace
pnrp

Resources

Encrypt Message