Calculate Route keeps ploting not the shortest route - here-api

I'm using HERE's calculate route API to present routes on the map. In a few places, I keep getting results that led me here as I am seemingly unable to achieve reasonable results. Near Warsaw, my route keeps turning to the north towards the city just to turn south-west that is back in the main direction whereas there is a straight road that would allow achieving the same. My users expect routes to be as straight as possible and I am not able to defend nor explain such deviations as this in route plotting.
Request parameteres:
url: 'https://route.api.here.com/routing/7.2/calculateroute.json',
method: 'get',
params:
{ app_id: 'is-it-possible-to-learn-this-power-?',
app_code: 'not-from-a-jedi',
mode:
'fastest;truck;traffic:disabled;tollroad:0,motorway:0,boatFerry:0,tunnel:0,dirtRoad:0,park:0',
waypoint0: '54.11025,22.96542',
waypoint1: '49.19168,16.65446',
waypoint2: '49.59958,17.26838',
avoidSeasonalClosures: true,
language: 'pl-pl',
excludeCountries: 'CHE,DEU',
metricSystem: 'metric',
legAttributes: 'length,travelTime',
jsonAttributes: 9,
routeAttributes: 'shape,legs',
limitedWeight: 40 }
}
It is worth noting that at first I was convinced that I get this result because of the traffic settings, but it turn out no matter which option (concerning traffic) do I choose I always end up with what it look like the same route shape.
Result on map:
Result near the city:
My question is: is there a way to achieve a straight route without detours such as this in my example or maybe this is totally acceptable route but I am unaware of the reason?

A solution to this problem was to soft exlude motorways and to avoidSeasonalClosures as there are some near Warsaw and Wroclaw.
Now request params look like this:
{ app_id: 'i-am-the-senate',
app_code: 'not-yet',
mode: 'fastest;truck;motorway:-2',
waypoint0: '54.11025,22.96542',
waypoint1: '49.19168,16.65446',
waypoint2: '49.59958,17.26838',
avoidSeasonalClosures: true,
avoidAreas: '53.204942,23.05379;53.100605,23.254131',
excludeCountries: 'CHE,DEU',
legAttributes: 'length,travelTime',
jsonAttributes: 9,
routeAttributes: 'shape,legs',
limitedWeight: 40 }
The excluded area is the road near and north to the city of Bialystok as this road is not optimal.

Related

Trying to use waypoints with JavaScript API

I'm new with MapHere, I see that with REST API side I can specify waipoints but I can't with JavaScript, I tried some parameters like 'via' but only admit one point:
var routingParameters = {
'routingMode': 'fast',
'transportMode': 'car',
// The start point of the route:
'origin': '36.8414197,-2.4628135',
'via': '37.9923795,-1.1305431',
// The end point of the route:
'destination': '40.4167047,-3.7035825',
// Include the route shape in the response
'return': 'polyline'
};
I saw an example on the main page of javascript web but I can't use waypoints:
var router = platform.getRoutingService(),
routeRequestParams = {
mode: 'fastest;car',
representation: 'display',
routeattributes: 'waypoints,summary,shape,legs',
maneuverattributes: 'direction,action',
waypoint0: '52.5160,13.3779', // Brandenburg Gate
waypoint1: '52.5206,13.3862' // Friedrichstraße Railway Station
};
Throwing the following error:
{"title":"Malformed request","status":400,"code":"E605001","cause":"Error while parsing request: 'origin' parameter is required\n","action":"","correlationId":"1c7bd525-b8af-4989-83a9-ab07f26a8c33"}
So, how I can send request for use waypoints?
EDIT
I saw the problem, when the .js create the url encode the second &via=
https://router.hereapi.com/v8/routes?xnlp=CL_JSMv3.1.18.1&apikey=***&routingMode=fast&transportMode=car&origin=50.1120%2C8.6834&destination=52.5309%2C13.3846&via=50.1234%2C8.7654%26via%3D51.2234%2C9.1123&return=polyline
If I decode & and = works perfectly
https://router.hereapi.com/v8/routes?xnlp=CL_JSMv3.1.18.1&apikey=***&routingMode=fast&transportMode=car&origin=50.1120%2C8.6834&destination=52.5309%2C13.3846&via=50.1234%2C8.7654&via=51.2234%2C9.1123&return=polyline
The JavaScript API does not yet (as of library version 3.1.18.1) support passing multiple waypoints, meaning passing an array of points to the via parameter. Your best bet around this lack of support would be to use the Routing REST API directly:
https://router.hereapi.com/v8/routes?
origin=52.550464,13.384223
&transportMode=car
&destination=52.477545,13.447395
&via=52.529791,13.401389
&via=52.513079,13.424392
&via=52.487581,13.425079
&apikey={YOUR_API_KEY}

Route Via Intermediate Waypoint - Passing a list of coordinates in via parameter

I need to pass a list of coordinates within parameters in via parameter, but i don't find the way. This is an example with only one pair of coordinates(lat, lng):
function calculateRoute (platform) {
var router = platform.getRoutingService(null, 8),
routeRequestParams = {
routingMode: 'fast',
transportMode: 'truck',
origin: '36.87689,-2.44138',
destination: '36.69630,-4.47968',
via: '38.99112,-1.86902', //LIST HERE!!!
return: 'polyline'
};
router.calculateRoute(
routeRequestParams,
onSuccessRoute,
onError
);
}
The url I'm hoping to get is like this:
https://router.hereapi.com/v8/routes?apikey=
{API_KEY}&routingMode=fast&transportMode=truck&origin=36.87689,-2.44138&via=38.99112,-1.86902&via=37.95862,-1.15538&destination=36.69630,-4.47968&return=polyline
As you can see via is repeat in the URL.
Many thanks!
The JavaScript API does not (yet) support multiple routing waypoints with regards to the Routing v8 API, meaning, it does not support passing a list of coordinates to the via parameter.
So your best bet is to target the Routing v8 REST API directly, like follow, and build a polyline out of the response:
# Note: line breaks and spaces are for readability only (they need to be removed)
https://router.hereapi.com/v8/routes?
origin=52.550464,13.384223
&transportMode=car
&destination=52.477545,13.447395
&via=52.529791,13.401389
&via=52.513079,13.424392
&via=52.487581,13.425079
&apikey={YOUR_API_KEY}
Don't know if it helps you, but
function calculateRouteFromAtoB (platform) {
var router = platform.getRoutingService(),
routeRequestParams = {
mode: 'fastest;car',
representation: 'display',
routeattributes : 'waypoints,summary,shape,legs',
maneuverattributes: 'direction,action',
waypoint0: '55.7520,37.6175',
waypoint1: '55.8941,37.4439',
waypoint2: '55.7982,37.9680'
};
router.calculateRoute(
routeRequestParams,
onSuccess,
onError
);
}
works for me.

password reset (Parse-server/Heroku) -> {"error":"unauthorized"}

On an app (ParseServer) that I have with HEROKU/mLab, providing password reset for the user.
After I click the link to reset my account password, I can only see this (in the browser):
{"error":"unauthorized"}
and am not able to reset my password as I should.
Does anyone know how to fix this problem?
For reference here is some code, which may be useful to better grasp the issue:
var api = new ParseServer({
databaseURI: databaseUri,
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAppId',
masterKey: process.env.MASTER_KEY || '',
serverURL: "https://myapp.herokuapp.com/parse",
publicServerURL: 'https://myapp.herokuapp.com/parse',
appName: 'TheApp',
liveQuery: {
classNames: ["Stuff_List"]
},
verifyUserEmails: true,
emailAdapter: {
module: '#parse/simple-mailgun-adapter',
options: {
fromAddress: 'sadguy#hmail.cor',
domain: 'dmn.net',
apiKey: process.env.EML_ADAPTER_KEY
}
}
});
I guess this could also happen to other people so I post the solution that I ended up finding. Hoping to avoid someone to lose a few hours like I did. The problem was in fact, rather basic (somewhat disappointing).
The issue was the APP_ID. It is used as part of the URL the user receives (for password resetting), so if it contains weird characters, that you may have chosen to make the ID complicated. It will break the URL. I guess, if one chooses "abcd1234" there will be no problem at all. But you may want to have something different for other reasons. So one has to find a good balance, being careful about the characters used in APP_ID.
Once I fixed that all went as expected.

iTunes Lookup API response is different for different clients

Right now it looks like a mystery. Please help me in solving it.
I use iTunes public API to fetch an album: "Metallica" by Metallica (see it in browser: US region, MV region). I construct the following URLs to fetch it via API:
US region https://itunes.apple.com/lookup?id=579372950&country=US&entity=album - works
MV region https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album - doesn't work
Here's the actual behaviour I observe:
If I query GET https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album in a Spring app (using RestTemplate + Jackson HttpMessageConverter) I get an empty response:
{
"resultCount":0,
"results": []
}
If I navigate to https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album in a browser I get a file download prompt. The file contains an empty response:
{
"resultCount":0,
"results": []
}
If I query API using HttpPie http get https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album I get a non-empty response !!!
{
"resultCount": 1,
"results": [
{
"amgArtistId": 4906,
"artistId": 3996865,
"artistName": "Metallica",
"artistViewUrl": "https://music.apple.com/us/artist/metallica/3996865?uo=4",
"artworkUrl100": "https://is1-ssl.mzstatic.com/image/thumb/Music/v4/0b/9c/d2/0b9cd2e7-6e76-8912-0357-14780cc2616a/source/100x100bb.jpg",
"artworkUrl60": "https://is1-ssl.mzstatic.com/image/thumb/Music/v4/0b/9c/d2/0b9cd2e7-6e76-8912-0357-14780cc2616a/source/60x60bb.jpg",
"collectionCensoredName": "Metallica",
"collectionExplicitness": "notExplicit",
"collectionId": 579372950,
"collectionName": "Metallica",
"collectionPrice": 9.99,
"collectionType": "Album",
"collectionViewUrl": "https://music.apple.com/us/album/metallica/579372950?uo=4",
"copyright": "℗ 1991 Blackened Recordings",
"country": "USA",
"currency": "USD",
"primaryGenreName": "Metal",
"releaseDate": "1991-08-12T07:00:00Z",
"trackCount": 13,
"wrapperType": "collection"
}
]
}
I tried it multiple times and the results seem to be consistent. I compared the requests and they seem to be identical.
Why does iTunes respond differently to different clients? I can't understand. What important detail am I missing?
Similar questions:
Spring RestTemplate getForObject URL not working for Apple iTunes - there's another problem (double encoding of the whitespace character).
This problem happens to the following regions (it's a complete list):
LI https://itunes.apple.com/lookup?id=579372950&country=LI&entity=album
MV https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album
MM https://itunes.apple.com/lookup?id=579372950&country=MM&entity=album
ET https://itunes.apple.com/lookup?id=579372950&country=ET&entity=album
RS https://itunes.apple.com/lookup?id=579372950&country=RS&entity=album
I spotted a difference:
http get 'https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album' -> empty response
curl 'https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album' -> empty response
http get https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album -> 1 album in response
curl https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album -> 1 album in response
if I don't use quotes around URL, the request is interpreted as GET https://itunes.apple.com/lookup?id=579372950. the default country is US and therefore I see 1 US album in response.

Get shortest distance of a route with several waypoints from Google Maps Api

I need to get the shortest route with several waypoints A, B, C, D. So I need the shortest route from A to B, the shortest from B to C and so on.
The way I understand is that the API should give me a few alternate routes from A to B, a few alternate routes from B to C... And at the end, I should go through all the leg and choose the shortest one.
But Google Direction API gives me only one route as a response. But if I ask the route from A to B, it returns 3 alternate routes, the same from B to C, etc.
My code:
directionsService.route({
origin: 'A',
destination: 'D',
waypoints: [
{
location: 'B',
stopover: true
},
{
location: 'C',
stopover: true
}],
travelMode: 'DRIVING'
, provideRouteAlternatives: true
}, callback);
the response I get is this
click to see image
I also tried using stopover: false and got the same result. I cannot use travelMode: 'WALKING' as the distance would be very different.
How can I solve this?
If you have waypoints, you can't get route alternatives.
One option would be to (if you don't know the way point order), request the route with optimizeWaypoints: true (to get the waypoint order), then request the routes between each set of waypoints with provideRouteAlternatives: true to get the options, then stitch them together. You will have to deal with the UI for selecting the alternative routes.

Resources