find the distances inside of circle radius

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
vedus
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 153
Joined: Tue Feb 26, 2013 9:23 am

find the distances inside of circle radius

Post by vedus » Tue Mar 18, 2014 11:39 pm

ok now i have a big problem with my customer.
My customer ask me to make a demo for him so.
The first demo was to find the current location of the customer and the distance from a specific store(that was easy with the example from dixie demo map)
Now my customer have be change opinion and she want to find the current location that is and some specific(like shoes store) stores inside of circle radius of 1000 meters.
what i have until now..
i have put the stores in sqlite database this fields.
Title,address,postal,phone,longitude,latitude for every store
my problem is how we find inside the radius this stores in 1000 meters and populate the meters for every one?
like my current location from the store 1 is 200 meters?
rdon't need to show up the locations in the map only i want the distances around..
really i don't know what i do here :( help guys

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: find the distances inside of circle radius

Post by Dixie » Wed Mar 19, 2014 12:41 am

Vedus...

You can run through the list of stores that you have and calculate the distance from where you are to each of the stores... here is a 'snippet' from a script I use that find places that are up to 30 miles from present location, but you could calculate for less and use kilometres instead of miles...

Code: Select all

get revDataFromQuery( tab, return, theDataRef, "SELECT * FROM " & theTrade && " ;")
   put it into temp
   
   /* calculate distance from where you are to each service listed */
   put thelat * pi/180 into lat1
   put thelong * pi/180 into lon1
   
   set itemDel to tab
   set numberformat to 0.00
   put empty into displayList
   put 1 into count
   
   repeat for each line thisLine in temp
      put item 4 of thisLine * pi/180 into lat2
      put item 5 of thisLine * pi/180 into lon2
   
      put (sin((lat2 -lat1)/2))^2 + cos(lat1) * cos(lat2) * (sin((lon2 - lon1)/2))^2 into a
      put 2 * atan2( sqrt(a), sqrt(1-a) ) into c
   
    --put 6373 * c into kms
      put 3961 * c into miles
      put thisLine & tab & miles into line count of displayList
      add 1 to count
   end repeat
   
   sort lines of displayList ascending numeric by last item of each
   
   repeat for each line thisLine in displayList
      if the last item of thisLine < 30 then
        delete the last item of thisLine
        put thisLine & cr after theFinalList
      end if	
   end repeat	

   put theFinalList	
   revCloseDataBase theDataRef

vedus
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 153
Joined: Tue Feb 26, 2013 9:23 am

Re: find the distances inside of circle radius

Post by vedus » Wed Mar 19, 2014 7:45 pm

thank you dixie the example is working nice,but,i have one more question.
from the example above we get the data,calculate the distance and show up somewhere.
is possible to calculate the distances and we get only this ?
like in the photo (blue Text) i have attached?
i have the datagrid ready like form!!
just for info i use the dblib from andre to polulate the data in my datagrids.
Screen Shot 2014-03-19 at 8.40.56 PM.png

Post Reply