Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Google Maps为geoJson文件中的点自定义标记_Javascript_Json_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 使用Google Maps为geoJson文件中的点自定义标记

Javascript 使用Google Maps为geoJson文件中的点自定义标记,javascript,json,google-maps,google-maps-api-3,Javascript,Json,Google Maps,Google Maps Api 3,我使用GeoJSON作为Google地图的数据源。我使用API的v3创建数据层,如下所示: <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script> <script> var map; function initialize() { //Initialise the map var myLatLng = new google.maps.LatLng(53.23147

我使用GeoJSON作为Google地图的数据源。我使用API的v3创建数据层,如下所示:

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>
var map;
function initialize() {

  //Initialise the map
  var myLatLng = new google.maps.LatLng(53.231472,-0.539783);
  map = new google.maps.Map(document.getElementById('map-canvas'), {
    zoom: 17,
    center: myLatLng,
    scrollwheel: false,
    panControl: false,
    zoomControl: false,
    scaleControl: true,
    disableDefaultUI: true
  });

  //Initialise base folder for icons
  var iconBase = '/static/images/icons/';

  //Load the JSON to show places
  map.data.loadGeoJson('/api/geo');

}

google.maps.event.addDomListener(window, 'load', initialize);
</script>

<div id="map-canvas"></div>
{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "icon": "/static/images/icons/map-marker-do.png",
        "coordinates": [
          -0.53743,
          53.23437
        ]
      },
      "properties": {
        "name": "Cathedral",
        "description": "One of Europe’s finest Gothic buildings, once the tallest building in the world that dominates Lincoln's skyline.",
        "icon": "/static/images/icons/map-marker-do.png"
      }
    }
  ]
}
我试图做的是让地图上的标记图标来自JSON中的“icon”属性,但无法弄清楚如何获取数据来更改默认标记。有人能提供一些建议吗?谢谢。

使用样式功能(样式功能使您能够根据特定功能应用样式)


在哪里添加标记?你如何处理
iconBase
?@MrUpsidown:他使用a,通过loadGeoJson加载的功能(例如标记/点)将由APIMy bad自动添加。我在JSON中看到了带有部分URL的iconBase,并没有进一步思考:-)Sweet的可能重复。非常感谢。:)
  map.data.setStyle(function(feature) {
    return {icon:feature.getProperty('icon')};
  });