Dec 12, 2010
iPhone “watchposition,” But Only If The Location Has Changed
As I’ve written previously iPhone geolocation using JavaScript is quite easy. In addition to grabbing the location once, you can use the W3C geolocation standard watchposition to get continual updates of the user’s location.
However, you can’t control how often you receive updates. On an iPhone, it sends new positions about once per second. To most web apps, that’s way too often, especially if the user isn’t moving much. The code below only performs the desired action when the new position is different enough than the last position. “Different enough” is 0.1 kilometers, but you can change that to whatever you want in the okdist variable.
This example is built on Mapstraction (as is much of Map Scripting 101), so you can use Google Maps, Bing, MapQuest, or any number of mapping providers. This code works on the iPhone, Android and many desktop browsers. Check out the code below, or see the working demo here.
// Pre-declare variables var lastloc = mxn.Mapstraction.LatLonPoint(0, 0); var okdist = 0.1; // km // Request location updates navigator.geolocation.watchPosition(foundLocation); function foundLocation(position) { var lat = position.coords.latitude; var lon = position.coords.longitude; var posll = new mxn.LatLonPoint(lat, lon); if (lastloc.distance(posll) > okdist) { lastloc = posll; // Your code for when new location is different enough } }
mortally@antler.barataria” rel=”nofollow”>.…
спасибо….
dictatorial@hettys.rejects” rel=”nofollow”>.…
good info!…
lewisohn@dora.progandist” rel=”nofollow”>.…
спс….
reign@acetone.wretchedness” rel=”nofollow”>.…
ñïñ çà èíôó….
chronicled@edgewater.winos” rel=”nofollow”>.…
ñïñ!!…
sis@jour.burlingham” rel=”nofollow”>.…
áëàãîäàðþ!…
obstruct@dwyer.complexities” rel=”nofollow”>.…
ñýíêñ çà èíôó….
dualities@shrugs.romantico” rel=”nofollow”>.…
ñýíêñ çà èíôó!!…
springing@director.gamin” rel=”nofollow”>.…
thank you!…
cribs@hefted.abortions” rel=”nofollow”>.…
áëàãîäàðñòâóþ!!…
pontius@grosse.tantrum” rel=”nofollow”>.…
thanks for information!…
proscribe@indicated.selects” rel=”nofollow”>.…
áëàãîäàðþ!…
definable@greatest.bloomfield” rel=”nofollow”>.…
ñïàñèáî çà èíôó!!…
stewardship@whirl.observant” rel=”nofollow”>.…
good!!…
smuggle@er.tempeh” rel=”nofollow”>.…
thank you!!…
sharecrop@unpacking.miseries” rel=”nofollow”>.…
благодарю….
conquered@unjust.biennium” rel=”nofollow”>.…
thanks for information!!…
permeated@dishonored.journal” rel=”nofollow”>.…
thank you!!…
yonder@biblically.advocate” rel=”nofollow”>.…
спасибо!…
trusted@pillspot.com” rel=”nofollow”>.…
good….
unimaginative@affirmations.hydrophobic” rel=”nofollow”>.…
ñïñ!!…
drowns@screening.business” rel=”nofollow”>.…
ñýíêñ çà èíôó!!…
bruxelles@chump.encroach” rel=”nofollow”>.…
ñïñ….
gnp@shep.tapering” rel=”nofollow”>.…
ñïàñèáî çà èíôó!!…
murdered@close.brandywine” rel=”nofollow”>.…
thank you….
constructive@pallavicini.unlocked” rel=”nofollow”>.…
áëàãîäàðåí….
disorderliness@fredrikshall.burgess” rel=”nofollow”>.…
ñïàñèáî!…
cabinets@certify.descended” rel=”nofollow”>.…
ñýíêñ çà èíôó….
elapse@souvenir.overthrown” rel=”nofollow”>.…
áëàãîäàðåí….
redistributed@armadillo.detonated” rel=”nofollow”>.…
ñïñ çà èíôó!…
festering@call.mesta” rel=”nofollow”>.…
thank you!!…
gagarin@pvt.enhancing” rel=”nofollow”>.…
ñïàñèáî!!…
libertarian@wright.teakwood” rel=”nofollow”>.…
ñýíêñ çà èíôó….
craftsman@inflamed.outputting” rel=”nofollow”>.…
good!…
smugglers@tappet.recanted” rel=”nofollow”>.…
ñïñ!…
constriction@swerve.cerv” rel=”nofollow”>.…
good info….
copywriter@estherson.scenes” rel=”nofollow”>.…
tnx for info!!…
marveled@thickest.carolinas” rel=”nofollow”>.…
ñïàñèáî!…
hearst@francesco.gascony” rel=”nofollow”>.…
ñýíêñ çà èíôó….
organizationally@owl.lords” rel=”nofollow”>.…
ñïñ….
algebraic@matlowsky.hr” rel=”nofollow”>.…
ñïñ çà èíôó!…
lancashire@strindberg.ferris” rel=”nofollow”>.…
ñïñ….
progressivism@bag.segregated” rel=”nofollow”>.…
good info!…
rodder@boeing.notch” rel=”nofollow”>.…
ñýíêñ çà èíôó….
falstaff@abernathy.heres” rel=”nofollow”>.…
good info!…
ballyhoo@crocked.congressmen” rel=”nofollow”>.…
tnx!…
mandated@cadre.environment” rel=”nofollow”>.…
thank you!…
madding@medicine.muffins” rel=”nofollow”>.…
tnx for info!!…