How to avoid road based on list of latitude & longitude

I’m using the Android file for offline routing. Link

and I’m trying to make a condition to avoid certain road using list of latitude & longitude. This is like there’s a unexpected road blockage or accident.

Thank you in advance. I do I appreciate more if there’s a complete code to study. Sorry for being newbie.

See the custom weighting example or in the master branch we’ve developed a more integrated solution for that (currently limited to changes that you know up-front or single thread applications)

Sorry for being newbie.

No problem. You can find getting started material in the documentation and if something is unclear we should improve this docs.

Sorry sir, I really need help following the instruction.

I just follow to test the weighting. Please see the screenshot

There are red in the code.

WeightingMap wMap,

String weighting = wMap.getWeighting();

I cant fix or make solution how it will be. Or i just missing something. The documentation is good, I just making a hard time doin it for the first time.

Another thing, am I doing it right declaring a GPS point

forbiddenEdges = 52.492999, 13.387924;

You can’t do this in Java :slight_smile: … create instances of GHPoint and then look them up using the LocationIndex (hopper.getLocationIndex), where you then get the edge IDs to be added to the forbiddenEdges.

Sorry sir, I can’t figure out how it will done. Is there any sample source code available to look on? My goal is just to have a offline routing that can set to avoid specific road (using gps point). Thank you in advance

Hi, I have a requirements like yours, which avoid road using latitude and longitude.
After looking a custom weight, it’s quite unclear about that. But I got this documentation
[Documentation - GraphHopper Directions API],

You can code like this

Hopefully help !!

(Documentation - GraphHopper Directions API)

The recommended way is now via custom profiles where you can define polygons that you cannot only exclude but also avoid or prefer: Examples For Customizable Routing - GraphHopper Directions API


I’ve tried like this

GHRequest req = new GHRequest(originLatitude, originLongitude, destinationLatitude, destinationLongitude)
		req.getHints().putObject("elevation", false);
		req.getHints().putObject("instructions", false);
		req.getHints().putObject("calc_points", generateRoutePath);
		if(blockedArea != null && !blockedArea.isEmpty()){
			GeometryFactory fact = new GeometryFactory();
			WKTReader reader = new WKTReader(fact);
			Map<String, JsonFeature> areasForbidden = new HashMap<>();
			CustomModel customModel = new CustomModel();

			try {				
				int index = 1;
				for(String area : blockedArea){
					Geometry polygonArea =;
					JsonFeature json = new JsonFeature();

					areasForbidden.put("forbiddenarea" + index, json);
					customModel.addToPriority(If("in_forbiddenarea"  + index, MULTIPLY, 0));
			} catch (Exception e) {
				// do something
			req.getHints().putObject(Parameters.CH.DISABLE, true);

But I got this errors …
The requested profile ‘car’ cannot be used with custom_model, because it has weighting=fastest

What should I do ?

You should use “new CustomProfile” instead of “new Profile”

It’s works … thankyou …

Powered by Discourse