Matching Positions to the Road Network
The position matching tries to assign one single GPS position to a segment on a digital map.
Benefits
- Consider the heading of the positions.
- Get the id of a matching segment for further use cases like custom Feature Layers.
Prerequisites
Please ensure following prerequisites are fulfilled before you start with the use case:
- Installed and licensed PTV xMatch Service
Programming Guide
The following sample illustrates the basic steps that are necessary to match a GPS position with the matchPositions API and visualize it on the map:
var map = new L.Map('map', {
center: [49.61, 6.125],
zoom: 13
});
// Add tile layer to map
var tileUrl = xServerUrl + '/services/rest/XMap/tile/{z}/{x}/{y}';
var tileLayer = new L.TileLayer(tileUrl, {
minZoom: 3,
maxZoom: 18,
noWrap: true
}).addTo(map);
var outputString='';
function matchPosition(position) {
xmatch.matchPositions({
"positions": [ position ],
"geometryOptions": {
"responseGeometryTypes": ["GEOJSON"]
}
}, function(response, exception) {
for(var i = 0; i < response.matchedPositions.length; ++i) {
var geoJson = response.matchedPositions[i].matchedSegment.polyline.geoJSON;
displayGeoJson(geoJson);
}
print("Positions matched: " + response.matchedPositions.length);
});
}
function displayGeoJson(geoJson) {
var jsonObject = JSON.parse(geoJson);
var geoJsonLayer = new L.GeoJSON(jsonObject, {
style: {
color: '#2882C8',
weight: 8
}
}).addTo(map);
map.fitBounds(geoJsonLayer.getBounds());
};
var position = {
"coordinate": { "x": 6.097592281341554, "y": 49.60986178122983 },
"heading": 10
};
matchPosition(position);
Related Topics
The following topics might be relevant for this use case.