On Aug 20, 11:47 am, chris <[email protected]> wrote:
>
> After five minutes of head scratching, I remembered something I
> learned when working with javascript last time. It tends to treat,
> what would appear to be integers, as strings.
Well, retrieving a string from XML gets a String, even if it's a
string of digits.
> In order to make it work, I had to first perform a mathematical
> operation on the string, to force javascript to recognise it as an
> integer:
>
> var zoomLevel = markers[i].getAttribute("zoomLevel");
> zoomLevel = zoomLevel / 1;
That doesn't actually force it to become an integer. While it works
for your data, if your zoomLevel attribute had been "13.4" for some
reason then it would be calculated as 13.4.
The best way of forcing something to be an integer is to use the
static method which is designed for it:
var zoomLevel = parseInt(markers[i].getAttribute("zoomLevel"));
Note that neither method will cope with a string which does not start
with a digit, although parseInt behaves better with mixed strings:
"A"/1 = NaN
parseInt("A") = NaN
"13.4A"/1 = NaN
parseInt("13.4A") = 13
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
-~----------~----~----~----~------~----~------~--~---