androidmysqlgoogle-maps-api-3gpscordova-2.0.0

How to store a gps coordinates in mysql, and then retrieve it without time lag?


I have completed a phonegap app which pools gps cordinate data every 10 sec to the server. now according to the calculations 8 hours of tracking it will store around 8*60*6=2880 records per user. my current requirement is limited to use of 20 user. (basically it tracks a users rout travelled)

There are two parts to the question:

I am having good results with 90 or so points, for one of my demos, but the enormous 2880 records per user per 8 hours is what worries me.

Thanks


EDIT 1
Although this is an old question , I recently worked on a project where I displayed about 10K points on the map, I hope my observations would help the future visitors:


Solution

  • So here is a possible solution:

    First of all, you need to find out how many points Google Maps API can handle and still show the line. I think this will just take some testing or researching. Anyways once you find your magical number of points to display to plot your path then take that number and multiply it by 2/3.

    For instance if a good path needs have say 90 points then calculate 90*2/3

    The reason for 2/3 is that the following loop will return a max number of points that is averagely equal to 3/2 times the variable we use so using. 60 would give us on average 90 plots. There is a case where the most returned plots would be (2 * (magical number of points)) - 1 for instance say we want on average of 90 points then we could in some rare cases have (2*(90*2/3))-1 = 119 points You will just have to do some testing after implementation to make sure that your magical number of points works good for maps with 2/3 of the magical number of points and 2 * magical number of points -1. I hope this isn't too confusing... I tried to explain as best I can.

    The rest of this is going to be sudo code. You will have to adapt it for whatever language you connect to MySQL with:

    //get the total number of rows returned
    var total_rows = mysql->num_rows;
    //calculate max to be 2/3 times your magic number for max plots, i.e. 90
    var max_plots = 90*2/3;
    //define empty plots array to fill with coordinates
    var plots = array();
    //check if total_rows is less than max_plots then:
    if(total_rows > max_plots){
      //find the quotient of the the divident total_rows and the divisor max_plots rounded down to the nearest whole int
      var quotient = floor(total_rows/max_plots);
      //define variable i to use in loop
      var i = 1;
      //loop through returned rows
      while(row = mysql->fetch_row()){
        //return only rows that are the first, last, or are dividable by the quotient evenly; Note: if your language supports it, use the Modulus operator like (i % quotient) == 0 for the last or statement.
        if(i == 1 || 1 == total_rows || (i - (i * (floor(i/quotient)))) == 0){
          //set plots to use on map
          plots[] = array(
            'lat' => row['lat'],
            'lon' => row['lon'],
          );
        }
        //increment counting variable
        i++;
      }
    // else if total_rows less than or equal to max_plots retrieve all plots
    } else {
      while(row = mysql->fetch_row()){
        plots[] = array(
          'lat' => row['lat'],
          'lon' => row['lon'],
        );
      }
    }
    

    This may not be the best way as it still requires to retrieve all of the rows from the database, but it does solve how to only print a selected maximum amount evenly spaced on the Google map.

    Note: Be sure that your query orders the rows by an auto incrementing key or some other way so that the plots will be in order that they were entered into the database.

    The most detailed maps would be a map with (2 * magic_plot_number) - 1 and your least details map would contain magic_plot_number or if lower, the number of total_plots. That being said an 8 hour tracking would plot a path with points every 7 minutes and 51 seconds totaling 61 points over 8 hours using the magic plot number of 90. The more plots the closer number of points will be to 2/3 * the magic plot number

    I hope this helps you with this situation.