13 Replies Latest reply: Mar 18, 2014 12:03 PM by David Young RSS

    Distance on Googlemaps

    David Young

      I have read over all the great examples on creating a googlemaps and I have been successful. I have 6000 acct with latitude and longitude values. I have found some examples of how to calculate the distance between two acct.  The question I have is are there some examples of how I can select any account, plug in a distance and get all the accounts within that distance.  Please advise.

       

      David

        • Re: Distance on Googlemaps
          Christophe Brault

          Hi,

           

          Are you talking about straight line distance or traffic distance ?

          • Re: Distance on Googlemaps
            Christophe Brault

            I'll try to explain what i do in my app :

             

            I have a field called "CR" with longitude and latitude.

            I've defined an alternate State call CR1. I use a listBox with this alternate State to select only ONE CR

            then i show :

             

            In one straight table, all CR with the distance in km with this expression :

             

            if(CR=only({CR1}CR),0,

              if(isnull(atan2(sqrt(sqr(cos(latitude*pi()/180)*sin(longitude*pi()/180-Lon1))

                      +sqr(cos(Lat1)*sin(latitude*pi()/180)-sin(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1)))

                  ,sin(Lat1)*sin(latitude*pi()/180)+cos(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1))*6371), '999',

              num(atan2(sqrt(sqr(cos(latitude*pi()/180)*sin(longitude*pi()/180-Lon1))

                      +sqr(cos(Lat1)*sin(latitude*pi()/180)-sin(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1)))

                 ,sin(Lat1)*sin(latitude*pi()/180)+cos(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1))*6371

                  ,'0')))

             

            From this expression you can create a listbox with an expression like this one :

             

            =class(aggr(if(CR=only({CR1}CR),0,

              if(isnull(atan2(sqrt(sqr(cos(latitude*pi()/180)*sin(longitude*pi()/180-Lon1))

                      +sqr(cos(Lat1)*sin(latitude*pi()/180)-sin(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1)))

                  ,sin(Lat1)*sin(latitude*pi()/180)+cos(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1))*6371), '999',

              num(atan2(sqrt(sqr(cos(latitude*pi()/180)*sin(longitude*pi()/180-Lon1))

                      +sqr(cos(Lat1)*sin(latitude*pi()/180)-sin(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1)))

                 ,sin(Lat1)*sin(latitude*pi()/180)+cos(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1))*6371

                  ,'0')))

                  ,CR)

               ,10,'km')

             

            You can use it to filter in a map for example.

             

            In google map, i change the color of each point with this expression :

             

            =if(CR=only({CR1}CR),vGris,

            aggr( if(

              if(CR=only({CR1}CR),vGris,

              if(isnull(atan2(sqrt(sqr(cos(latitude*pi()/180)*sin(longitude*pi()/180-Lon1))

                      +sqr(cos(Lat1)*sin(latitude*pi()/180)-sin(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1)))

                  ,sin(Lat1)*sin(latitude*pi()/180)+cos(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1))*6371), '999',

              num(atan2(sqrt(sqr(cos(latitude*pi()/180)*sin(longitude*pi()/180-Lon1))

                      +sqr(cos(Lat1)*sin(latitude*pi()/180)-sin(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1)))

                 ,sin(Lat1)*sin(latitude*pi()/180)+cos(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1))*6371

                  ,'0')))<=10,Color(1),

                  if(

              if(CR=only({CR1}CR),vGris,

              if(isnull(atan2(sqrt(sqr(cos(latitude*pi()/180)*sin(longitude*pi()/180-Lon1))

                      +sqr(cos(Lat1)*sin(latitude*pi()/180)-sin(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1)))

                  ,sin(Lat1)*sin(latitude*pi()/180)+cos(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1))*6371), '999',

              num(atan2(sqrt(sqr(cos(latitude*pi()/180)*sin(longitude*pi()/180-Lon1))

                      +sqr(cos(Lat1)*sin(latitude*pi()/180)-sin(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1)))

                 ,sin(Lat1)*sin(latitude*pi()/180)+cos(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1))*6371

                  ,'0')))<=20,color(2),

                  if(

              if(CR=only({CR1}CR),vGris,

              if(isnull(atan2(sqrt(sqr(cos(latitude*pi()/180)*sin(longitude*pi()/180-Lon1))

                      +sqr(cos(Lat1)*sin(latitude*pi()/180)-sin(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1)))

                  ,sin(Lat1)*sin(latitude*pi()/180)+cos(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1))*6371), '999',

              num(atan2(sqrt(sqr(cos(latitude*pi()/180)*sin(longitude*pi()/180-Lon1))

                      +sqr(cos(Lat1)*sin(latitude*pi()/180)-sin(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1)))

                 ,sin(Lat1)*sin(latitude*pi()/180)+cos(Lat1)*cos(latitude*pi()/180)*cos(longitude*pi()/180-Lon1))*6371

                  ,'0')))<=50,color(3),color(4))))

                  

                ,CR)

                )

             

            I hope this help. I can't share a qvw because i didn't achieve it with fake data...