2013-04-07 42 views
0

我想從我的foursquare Feed中獲取的座標,並利用它們在地圖中顯示的網站上使用。主要是作爲學習javascript和Mapbox的練習 - 我是新手。獲取從KML座標飼料與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 --> 
+0

一個問題:看起來像你的座標是錯誤的順序[從KML文件的座標沒有在谷歌地圖顯示正常(http://stackoverflow.com/questions/9866925/coordinates-from-a-kml-file - 不是 - 顯示 - 正常 - 中 - 谷歌 - 地圖) – geocodezip 2013-04-07 15:26:22

回答

0

您可以使用toGeoJSON將KML轉換爲GeoJSON for MapBox.js。