OSMBonusPack with Graphhopper routing API - java

I am building an application where I am using osmdroid with its bonus pack and mapnik for tiles. I want to be able to output shortest path between multiples points, and as a next step build paths considering time-frames. From my research it looks like Graphhopper Routing Optimization API is exactly what I need, but I can't figure out how to use it in my project properly. Since I am using os OSMBonusPack it looks like my only option is to set up Road Manager properly to be able to use routing optimization. Following tutorial for OSMBonusPack I am able to create Road manager and draw paths from one point to another, but not sure how to add optimization to find shortest path to it as well as set the road type to be "pedestrian" not a car. Any help will be highly appreciated. That's the code I am using to build a path between my points, pretty much exactly the same as tutorial:
ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
for (int i = 0; i < chosenAttractions.size(); i++) {
GeoPoint point = new GeoPoint(chosenAttractions.get(i).latitude, chosenAttractions.get(i).longitude);
waypoints.add(point);
}
if (count > 1) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
RoadManager roadManager = new GraphHopperRoadManager("fae5bf0a-402a-48b2-96ac-324e138f53dc", true);
// roadManager.addRequestOption("routeType=bicycle");
Road road = roadManager.getRoad(waypoints);
Polyline roadOverlay = RoadManager.buildRoadOverlay(road);
map.getOverlays().add(roadOverlay);
map.invalidate();
}
}

Turns out to use optimization or vehicle option of Routing API one has to pass it as an argument to addRequestOption function, for example:
roadManager.addRequestOption("vehicle=foot");
roadManager.addRequestOption("optimize=true");

Related

How to remove route in tomtom maps sdk?

Is there a way to remove the route without clearing the markers? Using function clear() is really bad.
tomtomMap.clear();
route = null;
origin = null;
destination = null;
Is there a function clearRoute() that do not clear the markers.
Take a look at the API reference
https://d221h2fa9j1k6s.cloudfront.net/downloads/mapssdk/APIReferences/JavaDocMap_2.4.376/index.html
I was able to test the function in my project and verified that it works.
tomtomMap.clearRoute() should solve your problem.
Regards!

Check if coordinate is in polygon for GoogleMaps API in JAVA

Is it possible to check if a location(Latitude, Longitude) is within a polygon using JAVA. I know this is possible in JavaScript. I found the Client library for Java but cant find ways to do this like ine JavaScript using e.g
containsLocation();
or if it is a way to use a url and do a http request with the url where i plot in the polygon and match it with the coordinates I want to check?
Ive tried the Client libs for Java but cant find any ways of doing it.
Any help is greatly appreciated.
PS: I must use Java
EDIT:
I found out this:
Polygon poly = new Polygon();
poly.addPoint(100, 100);
poly.addPoint(100, 0);
poly.addPoint(0, 0);
poly.addPoint(0, 100);
Point p = new Point(99, 99);
System.out.println(poly.contains(p));

Rendering a model basic on JPCT-AE with ARToolkit in Android

i want to render model via JPCT-AE and use the ARToolkit to realizing AR Application.
so , i inject the code as below into the ARToolkit Project:
Matrix projMatrix = new Matrix();
projMatrix.setDump(ARNativeActivity.getProjectM());
projMatrix.transformToGL();
SimpleVector translation = projMatrix.getTranslation();
SimpleVector dir = projMatrix.getZAxis();
SimpleVector up = projMatrix.getYAxis();
cameraController.setPosition(translation);
cameraController.setOrientation(dir, up);
Matrix transformM = new Matrix();
transformM .setDump(ARNativeActivity.getTransformationM());
transformM .transformToGL();
model.clearTranslation();
model.translate(transformM .getTranslation());
dump.setRow(3,0.0f,0.0f,0.0f,1.0f);
model.clearRotation();
model.setRotationMatrix(transformM );
And then , the model can be render on the screen but always lie on the mark in the screen, ever i using model.rotateX/Y/Z( (float)Math.PI/2 );
Actually, the matrix output from the ARToolkit::ARNativeActivity.getTransformationMatrix() is correct, and then i split this 4*4Matrix into translation Matrix and Rotation Matrix and set into the model like this:
model.translate(transformM .getTranslation());
model.setRotationMatrix(transformM );
But still no work.
I would suggest to organize better your code, and work with matrices to separate the transformations to make to your model and the transformations to place the model in the marker.
What I suggest is:
First, use an additional matrix. It may be called modelMatrix, as it will store the transformation done to the model (scale, rotation and translation).
Then, declare all matrices outside this method (it is for performance reasons only, but is recommended), and on each frame simply setIdentity to them:
projMatrix.setIdentity();
transformM.setIdentity();
modelM.setIdentity();
later, make the model transformations on the modelM matrix. This transformations will apply to the model, after placed on the marker.
modelM.rotateZ((float) Math.toRadians(-angle+180));
modelM.translate(movementX, movementY, 0);
then, multiply the modelM matrix by the trasnformM (this means you get all the transformations done, and move and rotate them as the transformM describes, which in our case means that all the transformations done to the model are moved on top of the marker).
//now multiply trasnformationMat * modelMat
modelM.matMul(trasnformM);
And finally, apply the rotation and translation to your model:
model.setRotationMatrix(modelM);
model.setTranslationMatrix(modelM);
so the whole code would look as:
projMatrix.setIdentity();
projMatrix.setDump(ARNativeActivity.getProjectM());
projMatrix.transformToGL();
SimpleVector translation = projMatrix.getTranslation();
SimpleVector dir = projMatrix.getZAxis();
SimpleVector up = projMatrix.getYAxis();
cameraController.setPosition(translation);
cameraController.setOrientation(dir, up);
model.clearTranslation();
model.clearRotation();
transformM.setIdentity();
transformM .setDump(ARNativeActivity.getTransformationM());
transformM .transformToGL();
modelM.setIdentity()
//do whatever you want to your model
modelM.rotateZ((float)Math.toRadians(180));
modelM.matMul(transformM);
model.setRotationMatrix(modelM );
model.setTranslationMatrix(modelM);
I strongly reccomend to look at this tutorial about matrices and OpenGL, it is not about JPCT, but all concepts may apply also to there, and it is what I've used to place correctly models in markers with the ARSimple example as you may see in this blog entry I made.
Hope this helps!

Roadmanager in osmdroid android

Hi I want to create offline map using osmdroid library.
I want to add two point in map and showing road between it.
For that I use this code
RoadManager roadManager = new OSRMRoadManager();
ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
myItemizedOverlay.addItem(MyItemizedOverlay.touchpoint, "touch", "touch");
waypoints.add(userlocation);//start point
waypoints.add(MyItemizedOverlay.touchpoint);// end point
Road road = roadManager.getRoad(waypoints);
PathOverlay roadOverlay = RoadManager.buildRoadOverlay(road, getApplicationContext());
mapView.getOverlays().add(roadOverlay);
mapView.invalidate();
but when I want to use it I'm getting this error message.
RoadManager cannot be resolved
I add osmdroid-android-4.2.jar and slf4j-android-1.5.8.jar
And I see this link and I try to import it but I'm giving this error message
build path contain duplicate entry src for project
Thanks for any help.
RoadManager is part of OSMBonusPack.
First of all, you should follow OSMBonusPack HowToInstall guide.
And then follow OSMBonusPack tutorial.

Android Libgdx TileAtlas

I am trying to add a Map to my libgdx app as a proof of concept. It seems that no matter how I make a packfile, the com.badlogic.gdx.graphics.g2d.tiled.TileAtlas constructor TileAtlas(TiledMap map, FileHandle inputDir) will not correctly read it. My Tile Map is simple and has only 2 tiles, and both the external gui and internal system will generate a packed file.
Here's the issue, either I name the packfile with a filename to match one of my images to satisfy line 2 below, or the method errors out. If I add 2 packfiles, one for each name of an image in my tile set, I find the Atlas isn't constructed correctly in memory. What am I missing here? Should there only ever be one tile in a tilemap?
Code from Libgdx:
for (TileSet set : map.tileSets) {
FileHandle packfile = getRelativeFileHandle(inputDir, removeExtension(set.imageName) + " packfile");
TextureAtlas textureAtlas = new TextureAtlas(packfile, packfile.parent(), false);
Array<AtlasRegion> atlasRegions = textureAtlas.findRegions(removeExtension(removePath(set.imageName)));
for (AtlasRegion reg : atlasRegions) {
regionsMap.put(reg.index + set.firstgid, reg);
if (!textures.contains(reg.getTexture())) {
textures.add(reg.getTexture());
}
}
}
com.badlogic.gdx.graphics.g2d.tiled --> It looks like you're using the old tiled API. I don't even think that package exists anymore, so you should probably download a newer version.
Check out this blog article. I haven't used the new API yet, but at a quick glance it looks much easier to load maps.

Categories