Code Monkey home page Code Monkey logo

directions-api-js-client's Introduction

GraphHopper Routing Engine

Build Status

GraphHopper is a fast and memory-efficient routing engine released under Apache License 2.0. It can be used as a Java library or standalone web server to calculate the distance, time, turn-by-turn instructions and many road attributes for a route between two or more points. Beyond this "A-to-B" routing it supports "snap to road", Isochrone calculation, mobile navigation and more. GraphHopper uses OpenStreetMap and GTFS data by default and it can import other data sources too.

Community

We have an open community and welcome everyone. Let us know your problems, use cases or just say hello. Please see our community guidelines.

Questions

All questions go to our forum where we also have subsections specially for developers, mobile usage, and our map matching component. You can also search Stackoverflow for answers.

Contribute

Read through our contributing guide for information on topics like finding and fixing bugs and improving our documentation or translations! We also have good first issues to get started with contribution.

Get Started

To get started you can try GraphHopper Maps, read through our documentation and install GraphHopper including the Maps UI locally.

Click to see older releases

Installation

To install the GraphHopper Maps UI and the web service locally you need a JVM (>= Java 17) and do:

wget https://repo1.maven.org/maven2/com/graphhopper/graphhopper-web/9.1/graphhopper-web-9.1.jar https://raw.githubusercontent.com/graphhopper/graphhopper/9.x/config-example.yml http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf
java -D"dw.graphhopper.datareader.file=berlin-latest.osm.pbf" -jar graphhopper*.jar server config-example.yml

After a while you see a log message with 'Server - Started', then go to http://localhost:8989/ and you'll see a map of Berlin. You should be able to right click on the map to create a route.

See the documentation that contains e.g. the elevation guide and the deployment guide.

Docker

The Docker images created by the community from the master branch can be found here (currently daily). See the Dockerfile for more details.

GraphHopper Maps

To see the road routing feature of GraphHopper in action please go to GraphHopper Maps.

GraphHopper Maps

GraphHopper Maps is an open source user interface, which you can find here. It can use this open source routing engine or the GraphHopper Directions API, which provides the Routing API, a Route Optimization API (based on jsprit), a fast Matrix API and an address search (based on photon). The photon project is also supported by the GraphHopper GmbH. Additionally to the GraphHopper Directions API, map tiles from various providers are used, with the default being Omniscale.

All this is available for free, via encrypted connections and from German servers - for a nice and private route planning experience!

Public Transit

Get started

Realtime Demo

Mobile Apps

Online

There is a web service that can be consumed by our navigation Android client.

android navigation demo app

Offline

Offline routing is no longer officially supported but should still work as Android supports most of Java. See version 1.0 with the Android demo and also see this pull request of the iOS fork including a demo for iOS.

simple routing

Analysis

Use isochrones to calculate and visualize the reachable area for a certain travel mode.

You can try the debug user interface at http://localhost:8989/maps/isochrone to see the /isochrone and /spt endpoint in action.

Isochrone API image

high precision reachability image

There is the map matching subproject to snap GPX traces to the road.

map-matching-example

Technical Overview

GraphHopper supports several routing algorithms, such as Dijkstra and A* and its bidirectional variants. Furthermore, it allows you to use Contraction Hierarchies (CH) very easily. We call this speed mode; without this CH preparation, we call it flexible mode.

The speed mode comes with very fast and lightweight (less RAM) responses and it does not use heuristics. However, only predefined vehicle profiles are possible and this additional CH preparation is time and resource consuming.

Then there is the hybrid mode which also requires more time and memory for the preparation, but it is much more flexible regarding changing properties per request or e.g. integrating traffic data. Furthermore, this hybrid mode is slower than the speed mode, but it is an order of magnitude faster than the flexible mode and uses less RAM for one request.

If the preparations exist you can switch between all modes at request time.

Read more about the technical details here.

License

We chose the Apache License to make it easy for you to embed GraphHopper in your products, even closed source. We suggest that you contribute back your changes, as GraphHopper evolves fast.

OpenStreetMap Support

OpenStreetMap is directly supported by GraphHopper. Without the amazing data from OpenStreetMap, GraphHopper wouldn't be possible at all. Other map data will need a custom import procedure, see e.g. Ordnance Survey, Shapefile like ESRI or Navteq.

Written in Java

GraphHopper is written in Java and officially runs on Linux, Mac OS X and Windows.

Maven

Embed GraphHopper with OpenStreetMap support into your Java application via the following snippet:

<dependency>
    <groupId>com.graphhopper</groupId>
    <artifactId>graphhopper-core</artifactId>
    <version>[LATEST-VERSION]</version>
</dependency>

See our example application to get started fast.

Customizable

You can customize GraphHopper with Java knowledge (with a high and low level API) and also without Java knowledge using the custom models.

Web API

With the web module, we provide code to query GraphHopper over HTTP and decrease bandwidth usage as much as possible. For that we use an efficient polyline encoding, the Ramer–Douglas–Peucker algorithm, and a simple GZIP servlet filter.

On the client side, we provide a Java and JavaScript client.

Desktop

GraphHopper also runs on the Desktop in a Java application without internet access. For debugging purposes GraphHopper can produce vector tiles, i.e. a visualization of the road network in the browser (see #1572). Also a more low level Swing-based UI is provided via MiniGraphUI in the tools module, see some visualizations done with it here. A fast and production-ready map visualization for the Desktop can be implemented via mapsforge or mapsforge vtm.

Features

  • Works out of the box with OpenStreetMap (osm/xml and pbf) and can be adapted to custom data
  • OpenStreetMap integration: stores and considers road type, speed limit, the surface, barriers, access restrictions, ferries, conditional access restrictions and more
  • GraphHopper is fast. And with the so called "Contraction Hierarchies" it can be even faster (enabled by default).
  • Memory efficient data structures, algorithms and the low and high level API is tuned towards ease of use and efficiency
  • Pre-built routing profiles: car, bike, racing bike, mountain bike, foot, hike, truck, bus, motorcycle, ...
  • Customization of these profiles are possible. Read about it here.
  • Provides a powerful web API that exposes the data from OpenStreetMap and allows customizing the vehicle profiles per request. With JavaScript and Java clients.
  • Provides map matching i.e. "snap to road".
  • Supports time-dependent public transit routing and reading GTFS.
  • Offers turn instructions in more than 45 languages. Contribute or improve here.
  • Displays and takes into account elevation data.
  • Supports alternative routes.
  • Supports turn costs and restrictions.
  • Offers country-specific routing via country rules.
  • Allows customizing routing behavior using custom areas.
  • The core uses only a few dependencies (hppc, jts, janino and slf4j).
  • Scales from small indoor-sized to world-wide-sized graphs.
  • Finds nearest point on street e.g. to get elevation or 'snap to road' or being used as spatial index (see #1485).
  • Calculates isochrones and shortest path trees.
  • Shows the whole road network in the browser for debugging purposes ("vector tile support"), see #1572.
  • Shows so called "path details" along a route like road_class or max_speed, see #1142 or the web documentation.
  • Written in Java and simple to start for developers via Maven.

directions-api-js-client's People

Contributors

alainfolletete avatar alilia avatar boldtrn avatar dependabot[bot] avatar karussell avatar michaz avatar oblonski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

directions-api-js-client's Issues

Better debugging

Its a bit hard to work with the npm package because when doRequest does not work it seems that the only return error message is that there is a bad request.

I was able to make a request work. Then I changed the address data for the services of the optimized route and all I get was "Bad Request".

After checking my code I saw that the lat/lng were strings instead of floats. After changing it it worked fine.

It would be nice if the returned error would give some hints what the problem could be.

Improve Map Matching usage

  • code examples for MapMatching (workaround: use live examples page)
  • instead of generating a GPX string and passing that into the ghMapMatching.doRequest(gpxString) we could try to make it more like the Routing JS client (using ghRouting.addPoint)

Graphhopper run time error “GraphHopperRouting is not a constructor”

I wanted to use graphhopper js client in my Ionic app, so following the instructions explained here I have installed the package using npm, then tried to use the routing API.
All I did was import this:

import {graphhopper, GraphHopperRouting, GHInput} from 'graphhopper-js-api-client';

And then wrote:

var defaultKey = "[key]";
var profile = "foot";
var host;
var ghRouting = new GraphHopperRouting({key: defaultKey, host: host, vehicle:profile,elevation:false})

ghRouting.addPoint(new GHInput(47.400905, 8.534317));
 ghRouting.addPoint(new GHInput(47.394108, 8.538265));

 ghRouting.doRequest().then(function(json){
   console.log("Result: " + json)
 }).catch(function(err){
   console.log(err.message)
 })

Exactly as the guide explained.
When I run the code, the following error is shown:

Runtime Error
 __WEBPACK_IMPORTED_MODULE_6_graphhopper_js_api_client__.GraphHopperRouting is not a constructor

Add Coordinate to PathDetails

We should resolve the indices of the PathDetails with actual coordinates similar to what we are doing with the instructions. This will make it easier for consumers to use the PahtDetails.

An error occured: Bad Request

An error occured: Bad Request - for url https://graphhopper.com/api/1/vrp/optimize?key=xxxxx

Hi

i create a local instance for testing localhost/graphhopper
i use the examples document for create my testing code i only modify the following code in examples, i put my key and try the demo localhost, working good with all items except when i change the coords lat and lon in the file tsp_lonlan_new.json
modify demo.js for set the center map

    $("#set_example_tsp").click(function () {
        $.getJSON("route-optimization-examples/tsp_lonlat_new.json?v=" + exampleVersion, function (jsonData) {

            clearMap();
            map.setView([4, -74], 6);
            $("#vrp-response").text("Calculating ...");
            ghOptimization.doRequest(jsonData)
                .then(optimizeResponse)
                .catch(optimizeError);
        });
    });

modify route-optimization-examples/tsp_lonlat_new.json for points

{
  "vehicles" : [{
    "vehicle_id" : "vehicle1",
    "start_address" : {
        "location_id" : "v1_startLoc",
        "lon": 4.713042,
        "lat": -74.05115
    },
    "type_id" : "vehicle_type_1"
  }],
  "vehicle_types" : [{
    "type_id" : "vehicle_type_1",
    "profile" : "car"
  }],
  "services" : [
    {
      "id": "b1",
      "name": "drink_bionade_in_rostock",
      "address": {
        "location_id": "loc_b1",
        "lon": 4.663407,
        "lat": -74.049069
      }
    },
    {
      "id": "b2",
      "name": "drink_cola_in_berlin",
      "address": {
        "location_id": "loc_b2",
        "lon": 4.744023,
        "lat": -74.064401
      }
    }
  ]
}

thanks for any help

Host @CDN

I think it would be a nice improvement to host the js-client at a CDN. An easy solution seems to be this CDN. Another example would be cdnjs.

Debugging error handling

I'm currently trying to update a project using the old client (raw JS files) and have utilized graphhopper-client.js but I'm getting:

Unhandled rejection [11]</GHUtil.prototype.extractError@http://localhost:9000/js/graphhopper-client.js:33:792
[16]</GraphHopperOptimization.prototype.doRawRequest/</<@http://localhost:9000/js/graphhopper-client.js:47:1505
[4]</Request.prototype.callback@http://localhost:9000/js/graphhopper-client.js:15:5622
Request/<@http://localhost:9000/js/graphhopper-client.js:15:2198
[2]</Emitter.prototype.emit@http://localhost:9000/js/graphhopper-client.js:9:1093
[4]</Request.prototype._end/t.onreadystatechange@http://localhost:9000/js/graphhopper-client.js:15:6965

I think here is something wrong in the client but could also be in my usage. How do I create and associate a map file for debugging?

Related graphhopper/directions-api-clients#13

Url seems to be build wrong with doRequest

Hey!

I am a bit confused. I am pretty sure I have done similar requests before but today I got the error that I have to specify at least 2 points.

My request object:

// Request Object

{
   "vehicles":[
      {
         "vehicle_id":"vehicle1",
         "start_address":{
            "location_id":"r8SvLjPsCxedseLBS",
            "lon":8.4573,
            "lat":47.18206
         },
         "type_id":"vehicle_type_1"
      }
   ],
   "vehicle_types":[
      {
         "type_id":"vehicle_type_1",
         "profile":"car"
      }
   ],
   "services":[
      {
         "id":"3MoDrkrjRXdFgKQ6S",
         "name":"Born Hansruedi_Niederbipp_Hansruedi Born_3.71ha_20WP",
         "address":{
            "location_id":"field-3MoDrkrjRXdFgKQ6S",
            "lon":7.71862,
            "lat":47.25543
         }
      },
      {
         "id":"WQ3Nv4KtPBNHvZGR7",
         "name":"Born Hansruedi_Niederbipp_Hansruedi Born_1.41ha_6WP",
         "address":{
            "location_id":"field-WQ3Nv4KtPBNHvZGR7",
            "lon":7.71651,
            "lat":47.26037
         }
      },
      {
         "id":"xMKGdQ3S4aXft8nk3",
         "name":"Feld 1_aesch_regina nu_3.92ha_0WP",
         "address":{
            "location_id":"field-xMKGdQ3S4aXft8nk3",
            "lon":47.48199,
            "lat":7.57499
         }
      }
   ]
}

After init the gh routing class in nodejs I am doing:

import GraphHopperOptimization from 'graphhopper-js-api-client/src/GraphHopperOptimization';

const ghRouting = new GraphHopperOptimization({ key: '..', ...});

ghRouting.doRequest(requestObject).then(() => { ... }).catch((e) => { .... })

this will return the error I wrote above. As far as I can see I have 3 points (if the errors references to the list of services) I am confused. Am I missing here something?

For better understanding this is the full error msg:

Specify at least 2 points - for url https://graphhopper.com/api/1/route?&vehicle=car&debug=false&locale=en&points_encoded=true&instructions=true&elevation=false&optimize=false&key=$$$KEY$$&vehicles.vehicle_id=vehicle1&vehicles.start_address.location_id=r8SvLjPsCxedseLBS&vehicles.start_address.lon=8.4573&vehicles.start_address.lat=47.18206&vehicles.type_id=vehicle_type_1&vehicle_types.type_id=vehicle_type_1&vehicle_types.profile=car&services.id=3MoDrkrjRXdFgKQ6S&services.name=Born%20Hansruedi_Niederbipp_Hansruedi%20Born_3.71ha_20WP&services.address.location_id=field-3MoDrkrjRXdFgKQ6S&services.address.lon=7.71862&services.address.lat=47.25543&services.id=WQ3Nv4KtPBNHvZGR7&services.name=Born%20Hansruedi_Niederbipp_Hansruedi%20Born_1.41ha_6WP&services.address.location_id=field-WQ3Nv4KtPBNHvZGR7&services.address.lon=7.71651&services.address.lat=47.26037&services.id=xMKGdQ3S4aXft8nk3&services.name=Feld%201_aesch_regina%20nu_3.92ha_0WP&services.address.location_id=field-xMKGdQ3S4aXft8nk3&services.address.lon=47.48199&services.address.lat=7.57499

It seems that services is not added as an array. instead the generated url is overwriting the services before so at the end there is only one services.name, services.address, ....

How to use Route Optimization API?

Hi, I've installed the js client and I would like to use Route Optimization API, but I'm not sure how I can use it.
I've required the whole client using require('graphhopper-js-api-client') and tried to call Routing with the parameter optimize:true as explained here :

var ghRouting = new GraphHopper.Routing({key: defaultKey, host: host, vehicle:profile,elevation:false,optimize:true})

The response I get are the points not sorted, they are in the order I've added them.
I've also tried using
var ghRouting = new GraphHopper.Optimization({key: defaultKey, host: host, vehicle_types:profile,elevation:false,calc_points:true})

But doesn't work. In the docs for Route Optimization API is not explained how to specifiy parameters for the constructor, so I'm a bit stuck.

How can I use this library in Angular?

Hello,

By the guideline, I did like below:

  1. Install
    npm install graphhopper-js-api-client --save

  2. Import libs I need only
    import * as GraphHopperRouting from 'graphhopper-js-api-client/src/GraphHopperRouting';
    import * as GHInput from 'graphhopper-js-api-client/src/GHInput';

  3. Call functions
    var ghRouting = new GraphHopperRouting({key: 'defaultKey', host: 'host', vehicle: 'car', elevation: false});

    // Setup your own Points
    ghRouting.addPoint(new GHInput(47.400905, 8.534317));
    ghRouting.addPoint(new GHInput(47.394108, 8.538265));

  4. Error comes out
    Uncaught ReferenceError: GraphHopperRouting is not defined at Object../node_modules/graphhopper-js-api-client/src/GraphHopperRouting.js (GraphHopperRouting.js:7) at __webpack_require__ (bootstrap:84)

Make Client more flexible

An issue with the client right now is that if we add new parameters to the API, we have to change the client as well.

It would be great if we could make the client a bit more flexible. We could dynamically convert the args object into a request string and only add special handling for a few parameters or maybe we add a second route method that accepts a URL so that users can write their own url conversion if needed.

make it possible to add multiple block_area

Current workaround is to hardcore the semicolon and keep all the parameters in one array as strings. E.g (for areas in the form of lat, lng, radius)

block_area = [[1,1,1],[3,4,5],...]           doesn’t work
block_area = [ "1", "1", "1”, ";3", ”4”, "5"...]        does

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.