Setting geofencing from coordinate 41.7523,12.8629

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Setting geofencing from coordinate 41.7523,12.8629



cant find scala code to find the list of coordinates which comes with in 1 mile distance from a particular coordinates 41.7523,12.8629.


scala


41.7523,12.8629



how can we geofencing for above given coordinate (spark scala)





what do you mean by "the code is not working"? do you get an error? do you get wrong answer? Please describe the output you get.
– Yaron
Aug 6 at 7:03




1 Answer
1



Using this function we can get one nearby point randomly within one mile radius:


nearby point randomly


one mile radius


def getPoints(xc:Double,yc:Double,radiusInMiles:Int)=
val ran = new scala.util.Random()
val conv = 1609.344
//Here, there are about 111,300 meters in a degree
val radiusIndeg = radiusInMiles*conv / 111300f;
val u = ran.nextDouble()
val v = ran.nextDouble()
val w = radiusIndeg*Math.sqrt(u)
val t = 2*Math.PI*v
val x = w*Math.cos(t)
val y = w*Math.sin(t)
val newX = x/Math.cos(Math.toRadians(yc))
val fLong = newX+xc
val fLat = y+yc
(fLong,fLat)



By calling the above function repeatedly in a for loop, we can get desired number of random points within 1 mile:


for(i<-1 to 30) yield getPoints(41.7523,12.8629,1)



To get 30 nearby points randomly,


In Scala REPL:
scala> for(i<-1 to 30) yield getPoints(41.7523,12.8629,1)
res25: scala.collection.immutable.IndexedSeq[(Double, Double)] = Vector((41.74982541032955,12.86481315224305), (41.754168266
959056,12.870364411375881), (41.75544877222746,12.85451037482713), (41.7612335738966,12.856539452781801), (41.76358834447362
,12.861061408964183), (41.763040037484664,12.867369860689339), (41.75110057115767,12.873299266989251), (41.74658541773817,12
.865223104625423), (41.74925109768552,12.868277572490877), (41.76504777008776,12.86109583406441), (41.75732730141462,12.8722
5307703036), (41.75762735062798,12.860633801016085), (41.75003276741254,12.856383089176347), (41.760707286583,12.85341268512
5267), (41.748073299368386,12.858209316913472), (41.76018412949083,12.866118423321987), (41.74213603200559,12.87308644848186
), (41.761324688000265,12.86506896052553), (41.749976...
scala> res25.foreach(println)
(41.74982541032955,12.86481315224305)
(41.754168266959056,12.870364411375881)
(41.75544877222746,12.85451037482713)
(41.7612335738966,12.856539452781801)
(41.76358834447362,12.861061408964183)
(41.763040037484664,12.867369860689339)
(41.75110057115767,12.873299266989251)
(41.74658541773817,12.865223104625423)
(41.74925109768552,12.868277572490877)
(41.76504777008776,12.86109583406441)
(41.75732730141462,12.87225307703036)
(41.75762735062798,12.860633801016085)
(41.75003276741254,12.856383089176347)
(41.760707286583,12.853412685125267)
(41.748073299368386,12.858209316913472)
(41.76018412949083,12.866118423321987)
(41.74213603200559,12.87308644848186)
(41.761324688000265,12.86506896052553)
(41.74997668526327,12.86038167090363)
(41.75228048449065,12.872686927175733)
(41.75972428137232,12.859596070561539)
(41.7562836928502,12.86187286720154)
(41.75715996439461,12.861374766455278)
(41.760604332388,12.867977103427238)
(41.74018421174905,12.865172431590485)
(41.74059829855585,12.86438943748021)
(41.7593627526156,12.873744103200057)
(41.747241804657264,12.8542871167178)
(41.76014663643563,12.858456116302811)
(41.740826160697715,12.867433800624394)

scala>





how we can get all the coordinates instead of 30 within one mile radius?
– Sheryl Brooke
Aug 23 at 6:25





How can one get all points? There will be infinite in number? You must fix a number first and you can find that many co-ordinates.
– RAGHHURAAMM
Aug 23 at 6:30





Just replace the number 30 in for loop with the desired number of co-ordinates.
– RAGHHURAAMM
Aug 23 at 6:31





i want all coordinates that comes under one mile .. i donot know how many it will come ?
– Sheryl Brooke
Aug 23 at 6:40






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS