View Full Version : Google Maps API and Javascript problem. Works in Firefox, why not IE?

10-27-2008, 07:05 PM
First, I apologize if you've seen this question elsewhere, but i wasn't sure exactly where to post it because it's facets overlap with respect to technical categorization.

I have implemented the Google Maps API and some javascript to create an application that determines product shipping distance using the Google Maps API and displays relevant content in a certain DOM element when the Google Map is refreshed.

Check it out here: http://www.schwebdesign.com/zooktemp/map5.php
Use Firefox first. It works fine doesn't it? It does for me. Firebug and the Web Developer Toolbar show NO javascript, css, or html errors of any kind.
That's exactly what it's supposed to do.

Using Internet Explorer 7:
The javascript for modifying the DOM element's content still works when the links on the left are clicked.
But the Map itself, calculation of Shipping distance, and display of relevant content in the respective DOM element upon finding shipping distance does not work. The map doesn't display.

It seems the jQuery code is working fine but not the Google maps code.

The error i receive is this:

Line: 4 Char: 9 Error: Object doesn't support this property or method. Code: 0

I'm assuming it's referring to http://www.schwebdesign.com/zooktemp/js/gmaps.js
Line 4 of gmaps.js contains only this:

Removing that line does not effect the line of the error or solve the problem.

please check out the source at: http://www.schwebdesign.com/zooktemp/map5.php
linked JS script i created is at: http://www.schwebdesign.com/zooktemp/js/gmaps.js

Why does this work flawlessly in Firefox yet die in IE? The code is perfect as far as i can tell.

Does anyone have any insight in to this?

Please, any advice is greatly greatly appreciated.

Here are some things i've tried:

adding DEFER to the script:
<script type="text/javascript" DEFER src="js/gmaps.js"></script>
Yielded no change.

disabling the code on line 4 that it seems to be referring to (map.enableGoogleBar();)
Yielded no change.

10-27-2008, 07:57 PM
dunno how perfect that is...

every time i click one of those links the refreshed contents walks a little down and to the left. repeated clicks move it more and more until it's behind the map. whatever the confusion is there could be mucking up the map.

10-27-2008, 08:05 PM
You have a clash of variable names.

rename your div from map to mapDiv or mapFoo or AmishBuggy.


10-27-2008, 08:32 PM
Thanks for the quick responses.

Thanks for your suggestion here as well as the other forum. I will try your suggestion asap and let you know how it worked. THanks!

Could you tell me what browser & version you were using that yielded the walking graphics for you?
You're right it's not perfect- it's only a template for purposes of pedagogy. My "perfect" was in reference to the fact that, for me at least, it worked 'perfectly' in FIrefox, but not IE. I was using firefox 3.0.3 and IE 7.0.6001.1800. I'm assuming (at least for now until i get the other problem fixed) that the problem you experience has to do with positioning of objects. hhmmm

10-27-2008, 08:40 PM
So I renamed the div to amishbuggy and that worked! Thank you very much!

So since i'm trying to learn here... i have a few other questions.

You mentioned i had a clash of variable names...

so do you mean IE had a problem basically with this:
map = new GMap2(document.getElementById("map"));

because "map", although supposedly referring to the div DOM element in map5.php, was clashing with the variable it was being called within?

Do you know, perhaps, why Firefox didn't have this clash. Is this a "bug" in IE? I'm wondering which browser's implementaitn of javascript was the 'correct' one.

Thank you again for your help. I will return to this forum for help in the future! (experts-exchange.com didn't help me at all this time)

10-27-2008, 08:47 PM
i only got the walking behavior in FF

FF 3.0 was acting correctly, as was IE7 in that regard.

10-27-2008, 08:48 PM
IE will let you reference page elements by ID with a global name. Back in the olden days it was okay to do that. I think Firefox will let you do it, but puts out a warning message into the console that you should use getElementById()

This is one reason I suggest to people to create your applications inside of a "namespace" and avoid using multiple global variables.


11-09-2010, 06:16 PM
I apologize in advance for reviving a dead thread, but my situation is very much similar to this one, I believe.

Here's my website, for reference: www.protectmyyard.com (http://www.protectmyyard.com)

My Google Map is under the 'Purchase' page.
I'm having the same problem described here. It works in FF and Safari, but not in IE (I get JS errors).

I saw the reference to conflicting variables for 'map'... but I'm not sure what files to change that in, as I'm not a pro-coder yet. Do I need to change 'map' to 'amishbuggy' (not specifically, but hypothetically) in the PHP, HTML, CSS, JS?

Also, this site was previously developed in Wordpress under the folder /newsite/... with that, the Map still references some PHP files from that folder. It seems the file referencing the PHP files is a JS file from Google. How do I get Google to update that particular JS to reference the newly located PHP files? Or do I update that reference somewhere else?