如何使用google maps api在GeoJSON功能标记'point'中显示图标?

时间:2015-09-08 14:00:37

标签: php google-maps-api-3 geojson marker

我正在尝试使用Google Maps JS API创建一个小应用程序。我正在使用数据层从GeoJSON文件加载一堆点。

该文件似乎正在正确加载,并且地图正在显示,但map.data.setstyle()中设置的图标将不会显示。

function init() {
    map = new google.maps.Map(document.getElementById('map'), {
        zoom: 17,
        center: new google.maps.LatLng(35.042248, -80.662319),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });
    map.data.setStyle(function(feature) {
        var theaterName = feature.getProperty('name');
        return {
            icon: {
                url: "maps.gstatic.com/mapfiles/ms2/micons/marina.png",
            }
            visible: true,
            clickable: true,
            title: theaterName
        };
    });
}

1 个答案:

答案 0 :(得分:0)

你在这里有一个额外的分号:

url: "maps.gstatic.com/mapfiles/ms2/micons/marina.png";,

应该是:

url: "maps.gstatic.com/mapfiles/ms2/micons/marina.png",

EDIT ::

好的,试试吧。

function init() {
    map = new google.maps.Map(document.getElementById('map'), {
        zoom: 17,
        center: new google.maps.LatLng(35.042248, -80.662319),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });
    marker = new google.maps.Marker({
        position: new google.maps.LatLng(35.042248, -80.662319),
        map: map,
        title: "Some Title",
        icon: "maps.gstatic.com/mapfiles/ms2/micons/marina.png"
    });
}