I am making a google map as part of a university project. here

and am having a few problems. Basicly for some reason my markers are not appearing as i don't think my array is being read.

Using the firebug plugin i am getting the following error message: markers is not defined
init()map_functions.js (line 24)
for(id in markers) { .

I don't really get how to solve this problem.

var centerLatitude = 51.523647;  //longittude and latitude coordinates and zoom geocodes
var centerLongitude = -0.146470;
var startZoom = 14;
var description = 'London';
 
function addMarker(latitude, longitude, description) {
var marker = new GMarker(new GLatLng(latitude, longitude));
 
GEvent.addListener(marker, 'click',
function() {
marker.openInfoWindowHtml(description);
}
);
 
map.addOverlay(marker);
}
 
function init() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
 
for(id in markers) {
addMarker(markers[id].latitude, markers[id].longitude, markers[id].name, markers[id].pcode);
}
}
}
 
window.onload = init;
window.onunload = GUnload;

my data looks like this.

var markers = [
	{
	'latitude': 51.51383,
	'longitude': -00.15246,
	'name': 'Balderton street',
	'pcode': 'W1'
	}
];

any help would be greatly appreciated as the project is due in on Friday!


dave

{
'latitude':  51.51626,
'longitude': -0.18732,
'name': 'Bishops Bridge Road',
'pcode': 'W2'
},
{
'latitude':  51.49681,
'longitude': -0.14168,
'name': 'Bressenden Place',
'pcode': 'SW1'
},

{
'latitude':  51.51360,
'longitude': -0.13581,
'name': 'Broadwick Street',
'pcode': 'W1'
},
{
'latitude':  51.50966,
'longitude': -0.08036,
'name': 'Byward Street',
'pcode': 'EC3'
},
{
'latitude':  51.53890,
'longitude': -0.14287,
'name': 'Camden High Street 176',
'pcode': 'NW1' 
},
{
'latitude':   51.46475,
'longitude': -0.16845,
'name': 'Clapham Junction/Station Approach',
'pcode': 'SW11' 
},
{   
'latitude':   51.51006,
'longitude': -0.28809,
'name': 'Ealing Common, Uxbridge Road ', 
'pcode': 'W1'
},
{   
'latitude':   51.49471,
'longitude': -0.18280,
'name': 'Gloucester Road',
'pcode': 'SW7' 
},
{   
'latitude':   51.51411,
'longitude': -0.13951,
'name': 'Great Marlborough Street', 
'pcode': 'W1'
},
{   
'latitude':   51.50651,
'longitude': -0.14291,
'name': 'Green Park underground station', 
'pcode': 'W1'
},
{   
'latitude':   51.52438,
'longitude':  -0.20144,
'name': 'Harrow Road', 
'pcode': 'W9'
},
{   
'latitude':   51.51706,
'longitude':  -0.11876,
'name': 'High Holborn', 
'pcode': 'WC1'
},
{   
'latitude':   51.50152,
'longitude':  -0.20335,
'name': 'Holland Park', 
'pcode': 'W8'
},
{   
'latitude':   51.50305,
'longitude':  -0.15333,
'name': 'Hyde Park Corner', 
'pcode': 'SW1'
},
{
'latitude':   51.51171,
'longitude':  -0.12164,
'name': 'London Transport Museum',
'pcode': 'WC1' 
},
{
'latitude':   51.51610,
'longitude':  - 0.18855,
'name': 'Westbourne Grove', 
'pcode': 'W2'
},
{
'latitude':   51.50358,
'longitude':    - 0.19181,
'name': 'kensington Church Street Bus Shelter Autoloo',                                                                                                                         'pcode': 'W8'
},


{                                                                                       
'latitude':   51.49866,
'longitude':     -0.19939,
'name': 'Kensington High Street', 
'pcode': 'W8'
},
{                                                                                           
'latitude':   51.50136,
'longitude':     -0.19412,
'name': 'Kensington Town Hall',
'pcode': 'W8' 
},
{                                                                                       
'latitude':    51.51057,
'longitude':     -0.13061,
'name': 'Leicester Square', 
'pcode': 'W1'
},
{                                                                                       
'latitude':    51.51057,
'longitude':     -0.08652,                                                                                                                      
'name': 'London Bridge Station', 
'pcode': 'SE1'
},
{                                                                                       
'latitude':    51.51274,
'longitude':     -0.16078,                                                                                                                      
'name': 'Marble Arch', 
'pcode': 'W1'
},
{                                                                                       
'latitude':    51.51137,
'longitude':     -0.17571,
'name': 'Kensington Gardens',
'pcode': 'W2'                                                                                                                                                                                                                                                   
},
{                                                                                       
'latitude':    51.52233,
'longitude':    -0.15571,
'name': 'Marylebone Road',
'pcode': 'NW1'                                                                                                                                                                                                                                                  
},
{                                                                                       
'latitude':    51.50731,
'longitude':    -0.14342,
'name': 'Mayfair Place',    
'pcode': 'W1'                                                                                                                                                                                                                                               
}

code:

var centerLatitude = 51.523647;  
var centerLongitude = -0.146470;
var startZoom = 14;
var description = 'London';

function addMarker(latitude, longitude, description) {
var marker = new GMarker(new GLatLng(latitude, longitude));

GEvent.addListener(marker, 'click',
function() {
marker.openInfoWindowHtml(description);
}
);

map.addOverlay(marker);
}

function init() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);

for(id in markers) {
addMarker(markers[id].latitude, markers[id].longitude, markers[id].name, markers[id].pcode);
}
}
}

window.onload = init;
window.onunload = GUnload;

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This question has already been answered. Start a new discussion instead.