• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculate all locations distance

#1
Hi
I have project named GPS Tracker
The one hundred device is active in my project
Each device send 24000 location to my server
In continue,i need calculate distance this locations for each device and save it
But number of records is high and if i use FOR statement for iterate array and calculate distance,the CPU maybe down
I try calculate distance between location when device send to server but locations is irregular and i cannot calculate exact distance
So i have to calculate distance after receive locations and insert into database and sort it and calculate distance

My code is :
PHP Code:
$this->db->order_by('time','ASC');
        
$this->db->where('device_id',$device_id);
        
$this->db->where('date',$date);
        
$locations $this->db->get('location')->result_array();

        
$last_location  =   '';
        
$distance       =   0;

        foreach (
$locations as $location) {

            if (
$last_location != '') {

                
$temp distance($last_location['latitude'],$last_location['longitude'],$location['latitude'],$location['longitude'],'m');

                if (!
is_nan($temp))
                    
$distance += $temp;

            }

            
$last_location $location;

        } 

Please suggest solution for me
Thanks
Reply


Messages In This Thread
Calculate all locations distance - by omid_student - 10-25-2019, 06:35 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.