decode

Function decode 

Source
pub fn decode(precision: u8, polyline: &str) -> PolylineIter<'_> 
Expand description

Decodes a polyline-encoded string into an iterator over geographic coordinates (latitude/longitude pairs).

This is a convenience function that wraps PolylineIter::new() and returns an iterator over points. The precision parameter specifies the number of decimal places in the coordinates (5 for polyline5, 6 for polyline6), with a maximum value of 7 which corresponds to ~1cm precision at the equator.

use polyline_iter::decode;

// Decode a polyline5 string (Google Maps standard format)
let points: Vec<_> = decode(5, "angrIk~inAgwDybH").collect();
assert_eq!(points, vec![(55.58513, 12.99958), (55.61461, 13.04627)]);

// Decode a polyline6 string (higher precision format)
let points: Vec<_> = decode(6, "avs_iB}xlxWissBw|zEu``AsxgCyoaAm_z@").collect();
assert_eq!(
    points,
    vec![
        (55.585137, 12.999583),
        (55.644854, 13.112187),
        (55.678161, 13.182229),
        (55.712222, 13.212444),
    ]
);

// Count points without collecting them
assert_eq!(decode(5, "angrIk~inAgwDybH").count(), 2);