突出显示Google Map Api中的所有铁路线

时间:2015-10-21 07:27:26

标签: javascript google-maps google-maps-api-3

我正在使用Google Map Api创建一个小网页,我想要突出显示Google Map Api中的所有铁路线。

我已尝试Styled Maps,但也许它没有铁路地图功能

2 个答案:

答案 0 :(得分:3)

要素类型transit.lines可能就是您要找的。

https://developers.google.com/maps/documentation/javascript/reference?hl=en#MapTypeStyleFeatureType

但它不仅包括铁路线(我想地铁,船等),但这仍然可能有所帮助,取决于你想要做什么......

JSFiddle demo



function initialize() {

    // Create an array of styles.
    var styles = [{
        "stylers": [{
            "saturation": -100
        }]
    }, {
        "featureType": "transit.line",
            "stylers": [{
            "saturation": 100
        }, {
            "color": "#ff3183"
        }]
    }];

    // Create a new StyledMapType object, passing it the array of styles, as well as the name to be displayed on the map type control.
    var styledMap = new google.maps.StyledMapType(styles, {
        name: "Styled Map"
    });

    // Create a map object, and include the MapTypeId to add to the map type control.
    var mapOptions = {
        zoom: 13,
        center: new google.maps.LatLng(40.7288, -74.1509),
        mapTypeControlOptions: {
            mapTypeIds: [google.maps.MapTypeId.TERRAIN, 'map_style']
        }
    };

    var map = new google.maps.Map(document.getElementById('map-canvas'),
    mapOptions);

    // Associate the styled map with the MapTypeId and set it to display.
    map.mapTypes.set('map_style', styledMap);
    map.setMapTypeId('map_style');
}

initialize();

#map-canvas {
    height: 400px;
}

<script src="//maps.google.com/maps/api/js?sensor=false"></script>
<div id="map-canvas"></div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

有一种创建地图的简单方法,您可以创建自己的谷歌地图,以便在谷歌地图上定义。通过此链接,您可以创建自己的谷歌地图,以便在谷歌地图上进行操作:

https://support.google.com/mymaps/answer/3024454?hl=en&amp%3Bref_topic=3188329

google map

只需单击三个点并选择嵌入地图选项,然后单击 html 标签后将生成您只需将其复制粘贴到您的项目中,您的谷歌地图就可以根据您的需要准备好