scala.js - Geolocation in scala js -
i have following function in scala.js program:
def geo():unit={ var window = document.defaultview val nav = window.navigator val geo: geolocation = nav.geolocation def onsuccess(p:position) = { println( s"latitude=${p.coords.latitude}") // latitude println( s"longitude=${p.coords.longitude}") // longitude } def onerror(p:positionerror) = println("error") geo.watchposition( onsuccess _, onerror _ ) }
i calling function main function. printing longitude , latitude continuously after period of time. wanted print 1 time. not able understand doing wrong here , should make stop printing again , again ?
you can use clearwatch
stop watching position observed one, this:
def geo(): unit = { val window = document.defaultview val nav = window.navigator val geo: geolocation = nav.geolocation var watchid: int = 0 def onsuccess(p:position) = { println(s"latitude=${p.coords.latitude}") // latitude println(s"longitude=${p.coords.longitude}") // longitude geo.clearwatch(watchid) // observe 1 position } def onerror(p:positionerror) = println("error") watchid = geo.watchposition(onsuccess _, onerror _) }
Comments
Post a Comment