Watching for change in location

Using the watchPosition function, you can constantly watch and get notification whenever the location of the device changes.

Method summary

watchPosition(callback, options)

  • returns – watchID (String)
  • params
    •  callback (function), options (object)

For instance,

<cffunction access="public" name="watchpos" returntype="void" >
<cfscript>
opt=cfclient.geolocation.getOptions();
watchId=cfclient.geolocation.
watchPosition(wtchposcallback,opt);
/*Populating the content of the <div> with the ID divId*/
document.getElementById('divId').innerHTML="Watch Id: "+watchId;

</cfscript>
</cffunction>

<cffunction access="public" name="wtchposcallback" returntype="void" >
<cfargument name="position">
<cfscript>
alert("Longitude "+position.coords.longitude+" Latitude
:"+position.coords.latitude);

</cfscript>
</cffunction>

Note: We have used alert() in the above example. alert() may not work on iOS devices.

Example

See Using the Geolocation APIs

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy