【问题标题】:How can I show the icon in the marker of GeoJSON feature 'point' using google maps api?如何使用谷歌地图 api 在 GeoJSON 特征“点”的标记中显示图标?
【发布时间】:2015-09-08 14:00:37
【问题描述】:

我正在尝试使用 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
        };
    });
}

【问题讨论】:

  • 嗨,Sara,欢迎来到 StackOverflow。提问时请务必发布相关代码。如果您需要帮助,请继续点击编辑按钮并在其中输入一些代码。
  • 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",} 可见:真,可点击:真,标题:剧院名 }; }); }
  • @sara - 我的意思是你问题下的编辑按钮。请不要在 copmments 中发布代码块。
  • 你添加了

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


【解决方案1】:

这里多了一个分号:

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

应该是:

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

编辑::

好的,试试这个。

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"
    });
}

【讨论】:

  • 非常深入的观察。
  • 如果可以的话,请给出带有一些图标的代码geojson google maps api示例!!!
  • 这个例子是为了点,但我问你geojson中的功能:(
  • @sara - 好的,看看我编辑的答案。请按我的答案打勾以标记它,如果有帮助,请按向上箭头也给我投票:)
猜你喜欢
  • 2013-07-05
  • 1970-01-01
  • 2013-04-20
  • 2014-03-05
  • 1970-01-01
  • 1970-01-01
  • 2018-05-25
  • 2014-05-25
  • 1970-01-01
相关资源
最近更新 更多