I am trying to get some json markers to display on my map.
The map is actually appearing but no pointers are being displayed and the position of the map is way off.
Here is the js code:
<script>
$('#map_canvas').gmap().bind('init', function() {
// This URL won't work on your localhost, so you need to change it
// see http://en.wikipedia.org/wiki/Same_origin_policy
$.getJSON( 'locations.json', function(data) {
$.each( data.markers, function(i, marker) {
$('#map_canvas').gmap('addMarker', {
'position': new google.maps.LatLng(marker.latitude, marker.longitude),
'bounds': true
}).click(function() {
$('#map_canvas').gmap('openInfoWindow', {'content': marker.content }, this);
});
});
});
});
</script>
And here is the contents of the json file:
{"locations":[{"id":"14","location":"(50.8765125,
-1.1504182944499557)"}]}
Is there anything wrong with the code?
From the structure of your
jsonfile I’d say your’re trying to access undefined properties of each item indata.markers.locationsis an array of objects with two properties:idis aStringandlocationsis anarrayof length 2. So why this code?Maybe you should try
First you should confirm your json output:
And post it in your question…
If it’s ok try like this:
… Actually I’m not sure why you use
data.markeralso and notdata.locations