【问题标题】:Get coordinates from KML feed to use with mapbox从 KML 提要中获取坐标以与 mapbox 一起使用
【发布时间】:2013-04-07 15:18:01
【问题描述】:

我正在尝试从我的foursquare 提要中获取坐标,并在地图中使用它们以显示在网站上。主要是作为学习 javascript 和 Mapbox 的练习——我是新手。

我使用了 mapbox 的“添加单个标记”代码和一些其他代码来循环遍历我的 KML 以查找坐标,since mapbox does not accept the KML

不知何故,我无法让它工作。非常感谢任何提示!

<!-- Foursquare map -->
<script>

    // get coordinates and place from Foursquare feed
    $(document).ready(function(){

        $.get("https://feeds.foursquare.com/history/6a46a109e06aa6d74d34b42b397806d5.kml?count=1", function(data){

            $(data).find("Placemark").each(function(index, value){

                coords = $(this).find("coordinates").text();
                place = $(this).find("name").text();
                pos = coords.split(",")

                    var features = [{
                        "geometry": { "type": "Point", "coordinates": pos[0], pos[1]},
                        "properties": { "place": place }       
                    }];
            });
        });
    });        

    // start Mapbox
    var map = mapbox.map('map-canvas').zoom(5).center({
        lat: 0,
        lon: 0
        });

  map.addLayer(mapbox.layer().id('rikwuts.map-0i5jiwdn'));

  // Create an empty markers layer
  var markerLayer = mapbox.markers.layer().features(features);

  // Add interaction to this marker layer. This
  // binds tooltips to each marker that has title
  // and description defined.
  mapbox.markers.interaction(markerLayer);
  map.addLayer(markerLayer);

  // Add a single feature to the markers layer.
  // You can use .features() to add multiple features.
  markerLayer.add_feature({
      geometry: {
          // The order of coordinates here is lon, lat. This is because
          // we use the GeoJSON specification for all marker features.
          // (lon, lat is also the internal order of KML and other geographic formats)
          coordinates: [ pos.lng, pos.lat ]
      },
      properties: {
          // these properties customize the look of the marker
          // see the simplestyle-spec for a full reference:
          // https://github.com/mapbox/simplestyle-spec
          'marker-color': '#00ff00',
          'marker-symbol': 'star-stroked',
          title: place,
          description: 'This is a single marker.'
      }
  });

  // Attribute map
  map.ui.attribution.add()
      .content('<a href="http://mapbox.com/about/maps">Thanks to Mapbox</a>');
</script>

<div id="map-canvas"></div>
<!-- END map -->

【问题讨论】:

标签: javascript jquery kml foursquare mapbox


【解决方案1】:

您可以使用toGeoJSON 将 KML 转换为 MapBox.js 的 GeoJSON。

【讨论】:

    猜你喜欢
    • 2012-07-11
    • 2012-11-22
    • 1970-01-01
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多