Map Matching Precision Enhancement


I’m developing an Android app for taxi drivers with real-time location updates sent to a server. I’ve integrated GraphHopper’s map matching module to snap GPS points to roads. While my implementation works, I’m seeking ways to enhance accuracy.

Challenge: Inaccurate Snapping at Intersections

In cases where a driver travels on road A intersecting road B, GraphHopper occasionally snaps to road B instead of road A.

I’ve tried solutions, such as prioritizing snap candidates sharing an edge with the previous snapped point. However, these adjustments haven’t completely resolved the issue and inaccuracies persist.


GraphHopper Init:

private fun setupGraphHopper(fileName: String, osmCacheDirectory: File) {
  val config = GraphHopperConfig()
  val osmFile = File(osmCacheDirectory, fileName)

  config.putObject("datareader.file", osmFile.absoluteFile.toString())
  config.putObject("graph.location", osmCacheDirectory.absolutePath)
  config.profiles = listOf(Profile("car_profile"))

  graphHopper = GraphHopper().init(config).importOrLoad()

Map Matching:

var prevEdge: Int? = null

private fun doMapMatching(point: Location) {
  val hints = PMap().apply { putObject("profile", "car_profile") }

  val mapMatching = MapMatching(graphHopper, hints).apply {

  val candidates = mapMatching.findCandidateSnaps(point.latitude, point.longitude)
  val result = if (prevEdge == null) {
     candidates.minByOrNull { it.queryDistance }
  } else {
     candidates.find { it.closestEdge.edge == prevEdge }
  if (result != null) {
     val snappedPoint = result.snappedPoint
      // ... other logic 
     prevEdge = result.closestEdge.edge

I’d appreciate any insights, recommendations or directions you can offer to help me refine my approach.