You are here

function _gmap_tracks_parse in GMap Addons 5

Same name and namespace in other branches
  1. 6 gmap_tracks/gmap_tracks.module \_gmap_tracks_parse()
  2. 7 gmap_tracks/gmap_tracks.module \_gmap_tracks_parse()

Parse a plt file into coordinates.

1 call to _gmap_tracks_parse()
gmap_tracks_gmap in gmap_tracks/gmap_tracks.module
Implementation of hook_gmap().

File

gmap_tracks/gmap_tracks.module, line 53
Track overlays for GMap.

Code

function _gmap_tracks_parse($track) {
  $points = array();
  $file = file_create_path($track);
  if ($file === FALSE) {
    drupal_set_message(t('Invalid path to track file!'));
  }
  else {
    if (!file_exists($file)) {
      drupal_set_message(t('Track file not found!'));
    }
    else {

      // @@@ Oversimplified OziExplorer PLT parser.
      // @@@ This needs improvement for various file types.
      if ($handle = fopen($file, 'r')) {
        while (!feof($handle)) {
          $line = fgets($handle, 4096);
          $line = explode(',', $line);
          if (count($line) == 7) {
            $points[] = array(
              (double) trim($line[0]),
              // latitude
              (double) trim($line[1]),
            );
          }
        }
        fclose($handle);
      }
    }
  }
  return $points;
}