json - Parsing geojson with jquery and placing it on google maps? -
everything seems working fine point of placing marker on map. pulls json file server extracts coordinates , applies them mylatlng "all need json file....for now". variable , coordinates can viewed , logged in console. still no marker. familiar map.data.loadgeojson('/static/json/data.json') , works fine plan on doing more advanced stuff data , need able make changes each individual marker down road not suite needs, far know.
heres code
function initialize() { var mapcanvas = document.getelementbyid('map-canvas'); var mapoptions = { center: new google.maps.latlng(39.50, -98.35), zoom: 4, maptypeid: google.maps.maptypeid.roadmap } var map = new google.maps.map(mapcanvas, mapoptions) $.getjson("/static/json/data.json", function(data) { $.each(data.features, function(key, val){ $.each(val.geometry, function(i, g){ if (g ==="point") { x = 1; } else{ var mylatlng = new google.maps.latlng(g[0], g[1]); var marker = new google.maps.marker({ position: mylatlng, map: map }); } }) }); }); } google.maps.event.adddomlistener(window, 'load', initialize);
geojson
{ "type": "featurecollection", "features": [ { "type": "feature", "properties": {}, "geometry": { "type": "point", "coordinates": [ -84.375, 36.31512514748051 ] } } ] }
mixed lat , long!. markers out of view. in antarctica!
should be
var mylatlng = new google.maps.latlng(g[1], g[0]);
instead of
var mylatlng = new google.maps.latlng(g[0], g[1]);
with changes code works great!
Comments
Post a Comment