Routing with avoid area and geofence / polygon - here-api

I want to avoid specific streets when using the routing API. I have data points to create a geofence or polygon to represent those specific streets.
The router API accepts only up to 20 bounding boxes. I tried to send 20 avoid area bounding boxes to represent the road, but the result is not reliable (e.g. on diagonal roads).
Is there a way to send a geofence/polygon instead of bounding boxes?
Or any other way to avoid certain streets?
Thank you very much

Please try to use avoid[segments] instead of avoid[areas] for avoiding specific roads. In the case of having too many roads to avoid, you can also put the avoid[segments] parameters into request body and send a POST request to the same endpoint.
In order to get the segmentId of the roads you would like to avoid, you can do a normal routing call with parameter spans=segmentId added and then look at the topologySegmentId attributes in spans section of the response.
https://developer.here.com/documentation/routing-api/api-reference-swagger.html

HERE Routing API now supports polygons for avoid area, https://www.here.com/learn/blog/routing-supports-polygons-for-avoid-areas

You have to make below calls for your usecase.
1>Rest call to get segmentId For the route.
https://router.hereapi.com/v8/routes? apikey={your_app_id}& origin=32.834496,74.81515& destination=32.811632,75.816037& return=polyline,summary,actions,instructions& spans=segmentId& transportMode=car&
2>Rest Call to get the get Route with avoid[segments]
https://router.hereapi.com/v8/routes? apikey={your_app_id}& origin=32.834496,74.81515& destination=32.811632,74.816037& return=polyline,summary,actions,instructions& spans=segmentId& transportMode=car& avoid[segments]=here:cm:segment:808368834,here:cm:segment:808095972

Related

Avoid Areas not working in Here Fleet Telematics

Im using the "avoidareas" parameter to remove some points from the initial trip. This method worked a couple of months ago, but now it returns the same route as the initial trip, ignoring the "avoidareas" parameter.
Here is the exemple im working with:
"https://fleet.ls.hereapi.com/2/calculateroute.json?apiKey={YOUR API KEY}&mode=fastest;truck;traffic:enabled;&currency=EUR&restTimes=EU&traverseGates=true&tollVehicleType=3&trailerType=2&trailersCount=1&length=13.6&width=2.4m&height=3m&limitedWeight=24000kg&legAttributes=li,-mn,sh&linkAttributes=wn,le,sh,-fc&mapMatchRadius=5000&ignoreWaypointVehicleRestriction=5000;0;all&departure=2022-09-08T16:00:00&waypoint0=40.613223,-3.2451044&waypoint1=39.919898,-8.634333&avoidareas41.6419,-5.16831;41.541900000000005,-5.06831"
Am i doing something wrong? Has something been updated?
The 'avoidAreas' feature works, but the request needs to be verified for the following:
the parameter name is in camelCase, so it should be 'avoidAreas', you are missing "=" sign right after avoidareas in your request url,
avoid area rectangle should be specified by latMax,lonMin;latMin,lonMax
A sample request looks like https://fleet.api.here.com/2/calculateroute.json?waypoint0=50.112698,8.675777&waypoint1=48.544180,9.662530&mode=fastest;truck;traffic:enabled&departure=2022-08-09T13:12:35&alternatives=0&weightPerAxle=3.25t&limitedWeight=7.5t&height=3.4m&width=2.5m&length=7.2m&trailersCount=1&avoidAreas=48.988757459020015,8.436328214242295;48.94714399157084,8.493687099461848
Thanks
/MS

Get shape of route link

Is there a possibility to get a shape, either polyline or coordinates, of route link by it's id using HERE API? I am calculating a road using calculate route endpoint by passing few avoid link's which I would like to show on the map. How can I achieve that? I was able to get tileX and tileY for each link using https://pde.cit.api.here.com/1/index.json but when I convert it to coordinates(per documentation) it gives me inaccurate results.
if you are using REST API, you can get shape with a request like this:
http://route.api.here.com/routing/7.2/calculateroute.json?
app_id=XXXX
&app_code=YYYYY
&mode=fastest;car
&routeattributes=shape
&waypoint0=48.98381310475713,2.5028838962316513
&waypoint1=48.83000339882299,2.2315230274810745

Multi Reverse Geocoding API 500 Error

https://reverse.geocoder.cit.api.here.com/6.2/multi-reversegeocode.json?app_id=MYID&app_code=MYCODE&gen=8&mode=retrieveAddress
Get Parameters
app_id=MYID
app_code=MYCODE
gen=8
mode=retrieveAddress
Headers
Content-Type=*
Cache-Control=no-cache
Post Body
prox=44.97750,-93.26899,50
prox=44.93909,-93.28083,50
Returns a 500 error with the response body being
{"type":"SystemError"}
This error doesn't provide me with any useful information as to what is wrong. Is there something wrong with my request or is this on Here's side?
here is a link to the API description that should help you with a successful post request: https://developer.here.com/rest-apis/documentation/geocoder/topics/request-first-multi-reverse-geocode.html
Looks like your post body doesn't include an "id". But you need that as otherwise you will not be able input to results, which is important when you don't limit maxresults to "1" and you are very likely get multiple results per input coordinate back.
I also recommend to set gen=9 and increase the radius from 50 to at least 250 meters. Because when your input point is further away than 50 meters from a road you can easily get back an area level fallback. Results are ranked by distance to input coordinate anyway, so a larger radius doesn't hurt at all.
id=0001&prox=44.97750,-93.26899,250
id=002&prox=44.93909,-93.28083,250

Acquired the building name using GPS Coordinates

I am writing an app to use GPS coordinates obtained by the cell phone itself to retrieve the building name of that location.
For example, if I use this http URL to request with Google Place API:
https://maps.googleapis.com/maps/api/place/search/json?location=40.805112,-73.960349&radius=10&sensor=false&key="YourKey"
I can only get the street name of this coordinate through this.
But if I type "40.805112,-73.960349" in maps.google.com. I can get the exact building name. SO I was wondering how can I use Google Map API to obtain the building name I want.
Thank you very much about this!!!
The first result in the request you provided contains "name" : "Church of Notre Dame", isn't this what you are looking for?
A better request if you are only interested in the place name at this location would be to use the rankby=distance parameter instead or radius and to filter by type=establishment:
https://maps.googleapis.com/maps/api/place/search/json?location=40.805112,-73.960349&rankby=distance&types=establishment&sensor=false&key=YOUR_API_KEY
This would return the closest place at the given location.

OpenLayers Vector Layer Maximum number of features

I was wondering if it is possible to limit the number of features you an draw on a vectorylayer. If I already have a polygon drawn, and go to draw another it will delete the first feature.
If not is it possible to add a listener to the vector layer, so that I can erase all features when clicking to draw?
Thanks!!!
You can't set max number of features on Vector Layer, but it has a whole lot of events where you can inject your own logic. Here are available events:
"beforefeatureadded", "beforefeaturesadded",
"featureadded", "featuresadded", "beforefeatureremoved",
"beforefeaturesremoved", "featureremoved", "featuresremoved",
"beforefeatureselected", "featureselected", "featureunselected",
"beforefeaturemodified", "featuremodified", "afterfeaturemodified",
"vertexmodified", "vertexremoved", "sketchstarted",
"sketchmodified", "sketchcomplete", "refresh"
You can use "beforefeatureadded" for instance:
your_vectror_layer.events.on({'beforefeatureadded': function(){
//Remove first feature or whatever you want to do
}});
you can make a button and when you click on it, it will remove all the features in your vector layer :
map.layers[1].removeAllFeatures();
Here 1 is the id of my layer (my vector layer is the second one after an OSM layer)
Good Luck !

Resources