1

I have a specific requirement wherein I have to display or highlight only railway stations in the map rather than the whole map. How can this be achieved? This is the code I tried:

<html>
    <head>
        <style type="text/css">
            html { height: 100% }
            body { height: 100%; margin: 0px; padding: 0px }
            #map_canvas { height: 100% }
        </style>
        <script type="text/javascript"
            src="http://maps.googleapis.com/maps/api/js?libraries=drawing&sensor=true">
        </script>
        <script type="text/javascript">
            function initialize() {
                // init map

                var myOptions = {
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };
                var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
                var drawingManager = new google.maps.drawing.DrawingManager();
                drawingManager.setMap(map);
                // init directions service
                var dirService = new google.maps.DirectionsService();
                var dirRenderer = new google.maps.DirectionsRenderer({suppressMarkers: true});
                dirRenderer.setMap(map);

                // highlight a street
                // highlight a street
                var request = {
                        origin: '',
                        destination: '',
                        travelMode: google.maps.TravelMode.TRANSIT
                    };

                dirService.route(request, function (response, status) {
                        if (status == google.maps.DirectionsStatus.OK) {
                            dirRenderer.setDirections(response);

                            var legs = response.routes[0].legs;
                            for (i = 0; i < legs.length; i++) {
                                var steps = legs[i].steps;
                                for (j = 0; j < steps.length; j++) {
                                    var transitMode = steps[j].travel_mode;

                                    if (transitMode == "TRANSIT") {
                                        var vehicle = steps[j].transit.line.vehicle.type;
                                        if (vehicle == "HEAVY_RAIL") {
                                            var nextSegment = steps[j].path;

                                            for (k = 0; k < nextSegment.length; k++) {
                                               // polyline.getPath().push(nextSegment[k]);
                                            }                            
                                        }
                                    }


                                }
                            }
                        }
                    });
            }
        </script>
    </head>
    <body onload="initialize()">
        <div id="map_canvas" style="width:100%; height:100%"></div>
    </body>
</html>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.