简体   繁体   中英

How to create an overlay of pathways on a map

I'm totally new to the Google Maps API's. I'm working on an application that should be similar to what you see here: http://www.wandelknooppunt.be/routeplanner?kaart=kempense-heide

I manage to add the nodes to the map, I don't see how to add the pathways between the nodes on the map. The route planning API seems no solution as the idea is the users should be able to create their route by clicking the nodes. Both the nodes and pathways are fixed.

So my question is how I can save a pathway (route) between two nodes in a database. (the pathway I want to store is not necessarily the fastest/shortest route between two nodes but it will always be a public route accessible by car)

OK, I found a solution by using KML .

1) First create a new map in Google maps. (In Google maps go to the menu > Your Places > Maps > Create Map) 2) Create the routes as you please using google maps. 3) Export your map 4) The KML find you just downloaded can be used as an overlay on your map with a function similar to this:

// Load the KML layer
            var KMLsrc = 'http://...../file.kml';
            loadKmlLayer(KMLsrc, map);
        }

        function loadKmlLayer(src, map) {
            var kmlLayer = new google.maps.KmlLayer(src, {
            suppressInfoWindows: true,
            preserveViewport: false,
            map: map
            });
        google.maps.event.addListener(kmlLayer, 'click', function(event) {
            var content = event.featureData.infoWindowHtml;
            var testimonial = document.getElementById('capture');
            testimonial.innerHTML = content;
            });
        }

PS The KML file needs to be in a location accessible by Google maps. A local file on your PC will not work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM