Giter VIP home page Giter VIP logo

msgpxcreator's Introduction

msGpxCreator

this script helps you simply create Gpx files and download it from your browser.

how to use

include_once "some/path/to/msGpxCreator/msGpxCreator.php";
$msGpxCreator = new msGpxCreator();
$msGpxCreator->setGpxTitle("Gpx title"); //Optional -> default: 'Gpx file' (recommended to be set)
$msGpxCreator->setFilePath("path/to/file/"); //Required
$msGpxCreator->setFileName("GPX-12365484964"); //Optional -> default: something like 'GPX-12365484964'
$msGpxCreator->setWaypoints($waypoints); //Required (array of stopovers)
$msGpxCreator->setTrackpoints($trackpoints); //Required (array of points along the route)
$msGpxCreator->setCreator("https://yourCompany.com"); //Optional -> default: 'https://github.com/hidden-shadow/msGpxCreator'
$file = $msGpxCreator->create();
$msGpxCreator->download();

waypoints and trackpoints parameters example

$waypoints = [
  [
    37.5284308,
    49.1073439,
    'description for waypoint #1'
  ],
  [
    37.5194876,
    49.034353,
    'description for waypoint #2'
  ],
  [
    37.6235526,
    48.7989885,
    'description for waypoint #3'
  ]
];

$trackpoints = [
  [
    37.52843,
    49.10734
  ],
  [
    37.52774,
    49.10903
  ],
  [
    37.5304,
    49.10892
  ]
];

how to get waypoints and trackpoints parameters from current map (google directions api)

function getWptAndTrkptForGpx() {
//  var directionsDisplay = new google.maps.DirectionsRenderer({...}); 
//  it's your DirectionsRenderer variable
  var currentDirections = directionsDisplay.getDirections();
  var route = currentDirections.routes[0];
  var trkpts = route.overview_path;
  var coord = [];
  coord['wpt'] = [];
  coord['trkpt'] = [];

  for ( var i = 0; i < route.legs.length; i++ ) {
    var LegLoc = route.legs[i].start_location;
    var lat = LegLoc.lat();
    var lng = LegLoc.lng();
    var address = route.legs[i].start_address;
    coord['wpt'][i] = [lat, lng, address];

    if ( i+1 == route.legs.length ) {
      var LegLoc = route.legs[i].end_location;
      var lat = LegLoc.lat();
      var lng = LegLoc.lng();
      var address = route.legs[i].end_address;
      coord['wpt'][i+1] = [lat, lng, address];
    }
  }

  for ( var i = 0; i < trkpts.length; i++ ) {
    var LegLoc = trkpts[i];
    var lat = LegLoc.lat();
    var lng = LegLoc.lng();
    coord['trkpt'][i] = [lat, lng];
  }

  return coord;
}

var coord = getWptAndTrkptForGpx();
var waypoints = JSON.stringify(coord.wpt);
var trackpoints = JSON.stringify(coord.trkpt);

msgpxcreator's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.