2014-12-03 67 views
0

与我的geoJson相关的标记未填充到我的地图上。如果我在http://geojsonlint.com/上运行我的geoJSON,它一切正常。如果我将我的geoJSON与Google Maps dev api 'https://storage.googleapis.com/maps-devrel/google.json'中的示例互换,那么它们的覆盖图会填充到我的地图上。有效的geoJson未填充Google地图标记

下面我运行http://localhost:3009/murals.json作为loadGeoJson的参数我也试过从本地文件运行test.json

我的地图.js文件

function initialize() { 
    var myLatlng = new google.maps.LatLng(40.0172679,-105.2839094); 
    var myOptions = { 
    zoom: 16, 
    center: myLatlng, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(
    document.getElementById('map'), myOptions 
); 
    map.data.loadGeoJson('http://localhost:3009/murals.json'); 
}; 

google.maps.event.addDomListener(window, "load", initialize()); 

我控制器(无疑会进行重构,但输出正确的格式以GeoJSON)

def index 
    @murals = Mural.all 
    muralHash = [] 
    @geojson = { type: "GeometryCollection", 
     geometries: muralHash 
    } 
     @murals.each do |mural, myHash = {:type => nil,:coordinates => nil}| 
     myHash["type"] = 'Point' 
     myHash["coordinates"] = [mural.longitude, mural.latitude] 

     muralHash << myHash 
     end 
    respond_to do |format| 
     format.html 
     format.json { render json: @geojson } 
    end 
    end 

GeoJSON的

{ "type":"GeometryCollection", 
     "geometries":[ 
     { 
      "type":"Point", 
      "coordinates":[-105.287685950293,40.0124034482671] 
     }, 
     { 
      "type":"Point", 
      "coordinates":[-105.196297724738,39.9935339839196] 
     }, 
     { 
      "type":"Point", 
      "coordinates":[-105.283136923804,40.0162490232761] 
     } 
     ] 
    } 
+0

请发布JSON – 2014-12-03 18:22:59

+0

@ Dr.Molle补充 – Jadam 2014-12-03 18:26:40

回答

1

的JSON是无效(与地图-API预期的格式有效),这将起作用:

{ 
    "type":"FeatureCollection", 
    "features":[ 
    { 
     "type":"Feature", 
     "geometry":{ 
     "type":"Point", 
     "coordinates":[-105.287685950293,40.0124034482671] 
     } 
    }, 
    { 
     "type":"Feature", 
     "geometry":{ 
     "type":"Point", 
     "coordinates":[-105.196297724738,39.9935339839196] 
     } 
    }, 
    { 
     "type":"Feature", 
     "geometry":{ 
     "type":"Point", 
     "coordinates":[-105.283136923804,40.0162490232761] 
     } 
    } 
    ] 
} 
+0

这不适合我。另外,当我在geoJSON linter中运行它时,它会失败。 – Jadam 2014-12-03 18:41:29

+1

http://jsfiddle.net/doktormolle/8tmw6mo8/ – 2014-12-03 18:48:04

+0

不得不在我的代码里钻一下我的代码,以便在那里获得它,但它正在运行。我认为相信geoJSON linter是一个不好的举动? – Jadam 2014-12-03 18:57:54