
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Combitrip API - Directions: Basic Example</title>
    <style>
        .ac-container {
            padding: 10px 10px 10px 20px;
            background: rgba(255, 255, 255, 0.5);
            position: absolute;
            z-index: 1000;
            left: 50px;
            top: 15px;
            width: 300px;
            border-radius: 6px;
        }

        .ac-container input{
            display: block;
            width: 100%;
            padding: 5px 8px;
            border-radius: 4px;
            border: 1px solid #ccc;
        }

        .ac-container label{
            position: absolute;
            left: 5px;
            line-height: 28px;
        }

        #ac-origin{
            margin-bottom: 5px;
        }

    </style>
</head>
<body>
<div id="osm-map" style="width: 100%; height: 100%;">
    <div class="ac-container">
        <label>A:</label>
        <input type="text" id="ac-origin"/>
        <label>B:</label>
        <input type="text" id="ac-destination"/>
    </div>
</div>

<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="https://www.combitrip.org/api/public/combitrip.maps.min.js?key=32a61ca69e22441db052df11ab8ba02b"></script>
<script src="https://www.combitrip.org/api/public/combitrip.geocomplete.min.js?key=32a61ca69e22441db052df11ab8ba02b"></script>

<script>
    var _origin, _destination, _mapInst;

    function route(){
        if (_origin && _destination){
            var origin_latlng = [_origin.lat(), _origin.lng()];
            var destination_latlng = [_destination.lat(), _destination.lng()];

            var mkOrig = _mapInst.iconMarker(origin_latlng, '/images/fromA.png', {iconSize: [35, 45], iconAnchor: [17, 45], addToMap: false});
            mkOrig.attachPopup('START ROUTE<span  style="color:red">!</span>');

            var mkDest = _mapInst.iconMarker(destination_latlng, '/images/toB.png', {iconSize: [35, 45], iconAnchor: [17, 45], addToMap: false});
            mkDest.attachPopup('END ROUTE<span  style="color:red">!</span>');

            _mapInst.route([origin_latlng, destination_latlng], {
                showItinerary: false,
                originMarker: mkOrig,
                destinationMarker: mkDest,
                lineOptions: {
                    styles: [
                        {color: '#85a9dd', weight: 4}
                    ]
                }
            });
        }
    }

    $("#ac-origin").abgeo({
        showCurrentLoc: true
    }).bind("abgeo:place_changed", function (event, result) {
        _origin = result.geometry.location;
        route();
    });

    $("#ac-destination").abgeo({
        showCurrentLoc: true
    }).bind("abgeo:place_changed", function (event, result) {
        _destination = result.geometry.location;
        route();
    });


    new ABOSM("osm-map", {
        center: [52.248624, 4.669728],
        zoom: 10
    }).ready(function (inst) {
        _mapInst = inst;
    });
</script>

</body>