On Dec 8, 2:06 pm, foxykav <[EMAIL PROTECTED]> wrote:
> Hi, I'm new to javascript and Google Maps API and I'm trying to load
> multiple markers from a hardcoded javascript array in the script. For
> some reason the map is not loading the markers. Do I have a syntax
> problem or something? I cannot see the problem.
var turns ["-37.782639, 145.227631", "-37.783745, 145.227417",
"-37.784317, 145.232834", "-37.793827, 145.235443"];
The Firefox Error Console tells you that that line is wrong, and
expects a semicolon after
var turns
because that's a valid command. To do what you want there should be an
equals sign in there. Javascript uses = for variable assignment:
var turns = ["-37.782639, 145.227631", "-37.783745, 145.227417",
"-37.784317, 145.232834", "-37.793827, 145.235443"];
However, bear in mind that once that works, you will be attempting to
create something like
var latlng = new GLatLng("-37.782639,145.227631");
and GLatLng does not take a string, but two numbers. Have a look
at .split(), which will split a string at a delimiting character --
comma in your case -- into an array of strings. You then need to use
parseFloat() to convert the strings to numbers.
Or, make your array an array of numbers and take two at a time to use
as coordinates.
var turns = [37,782639,145.227631,-37.783745,145.227417...]
Or, make your array an array of arrays:
var turns = [[37,782639,145.227631],[-37.783745,145.227417]...]
which is slightly more readable and provides ready-made numbers:
var latlng = new GLatLng(turns[i][0],turns[i][1]);
Andrew
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---