0

I am trying to create a hill finder application

Like this

The user enters a starting location, and an end location. With the end goal of displaying a chart with the elevations of the road in the trip

Currently, I have managed to get it to create a route between point A and point B. I needed to use routing, since in my use case, the user has to stay on the road and can't just draw a straight line

code so far:

RoadManager roadManager = new OSRMRoadManager(requireContext(), "MY_USER_AGENT");
ArrayList<GeoPoint> waypoints = new ArrayList<>();
waypoints.add(startPoint);
GeoPoint endPoint = new GeoPoint(48.069842, -1.712637);
waypoints.add(endPoint);
Road road = roadManager.getRoad(waypoints);
Polyline roadOverlay = RoadManager.buildRoadOverlay(road);
map.getOverlays().add(roadOverlay);
map.invalidate();
Drawable nodeIcon = getResources().getDrawable(R.drawable.ic_baseline_location_on_24);
for (int i=0; i<road.mNodes.size(); i++){
    RoadNode node = road.mNodes.get(i);
    Marker nodeMarker = new Marker(map);
    nodeMarker.setPosition(node.mLocation);
    nodeMarker.setIcon(nodeIcon);
    nodeMarker.setTitle("Step "+i);
    map.getOverlays().add(nodeMarker);
}

Took this from the guide on the osmdroid bonus pack github page

I already have a system in place to load elevations from coordinates elsewhere in the app. I just need to get the coordinates from the route. At least every 10 feet or so, not just the intersections

I'm hoping this is possible with osmdroid, especially since this has been done with google's apis. However, that code was not open, and I don't want to be charged per usage

My best guess was something with projection(), but I barely know how to use it

NOTE: I won't be using this for long distances, probably at most a mile is what the user would need

Bobabooy114
  • 55
  • 1
  • 7

1 Answers1

0

I don't think omsdroid can do this out of the box. However you can solve this:

roadOverlay.getPoints() will give you ArrayList containing the "turning" points. You can then apply some math to calculate what you need. I would do it like this:

  1. Calculate distance in feet between two turning points. Calculate distance between 2 GPS coordinates
  2. Divide the distance by 10 feet (as mentioned in your post) and subtract 1. You will get the number of points between the 2 turning points.
  3. Apply some more math to get lat and lng of each of the points on the road. You can inspire here. How to calculate the points between two given points and given distance? or Calculate point between two coordinates based on a percentage
  4. You can now use the elevation API for the points. Do not forget to get the elevation of the turning points, too.
  5. Get the next 2 turning points and repeat. :-)
Andrej S
  • 61
  • 8