SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript error in IE7 when embedding google maps

    I am facing a javascript error in IE7 when trying to embed google map on a page. Firefox and Opera are displaying the map properly, but not IE7 which instead gives the following error:

    Line: 19
    Char: 2
    Error: Object doesn't support this property or method.
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
    <html>
    <head>
    <title>Map</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAUrvJiGLiw9De7R0N_2_bjBQWRJvwqkqS2safuwRocnXIIkx4WhS6E2SAkFKzcx19P9i4zLbNSNDjZw" type="text/javascript"></script>  
    
    <script type="text/javascript">
    
    var map;
    var gmarker = {};
    var targets = {};
    
    function init_map() {
    	map = new GMap2(document.getElementById('map'));
    	map.addControl(new GSmallZoomControl());
    
    	var lats = items.map(function(info) { return info.lat }).sort(function(a,b){return a - b});
    	var lngs = items.map(function(info) { return info.lng }).sort(function(a,b){return a - b});
    	var l = lats.length;
    	var s = lats[Math.round((l-1) * 0)];
    	var w = lngs[Math.round((l-1) * 0)];
    	var n = lats[Math.round((l-1) * 0.90)];
    	var e = lngs[Math.round((l-1) * 0.90)];
    	var pad = 0;
    
    	bounds = new GLatLngBounds(
    		new GLatLng(s,w),
    		new GLatLng(n,e)
    	);
    	map.setCenter(
    		bounds.getCenter(),
    		map.getBoundsZoomLevel(bounds)
    	);
    	for(i=0; i < items.length; i++) {
    		var target = items[i];
    		addMarker(target);
    	}
    }
    
    window.onload = init_map;
    window.onunload = GUnload;
    
    function addMarker(target) {
    	var marker = new GMarker(new GLatLng(target.lat, target.lng));
    	GEvent.addListener(marker, 'click',
    		function() { marker.openInfoWindowHtml(target.html); } 
    	);  
    	map.addOverlay(marker);
    
    	gmarker[target.id] = marker;
    	targets[target.id] = target;
    }
    
    function selectLocation(i) {
    	var marker = gmarker[i];
    	var target = targets[i];
    	map.panTo(new GLatLng(target.lat, target.lng));
    	marker.openInfoWindowHtml(target.html);
    }
    
    </script>
    
    </head>
    
    <body>
    
    <script type="text/javascript">
    var items = [
    {
    	id: 1,
    	html: 'Location 1 Details Here',
    	lng: 30.6,
    	lat: 38.1
    },
    {
    	id: 2,
    	html: 'Location 2 Details Here',
    	lng: 30.5,
    	lat: 38.2
    },
    {
    	id: 3,
    	html: 'Location 3 Details Here',
    	lng: 30.7,
    	lat: 38.2
    }
    ]
    </script>
    
    <div id="map" style="width: 350px; height: 300px;"></div>
    
    </body>
    </html>
    Apparently, these lines are causing the problem:
    HTML Code:
    	var lats = items.map(function(info) { return info.lat }).sort(function(a,b){return a - b});
    	var lngs = items.map(function(info) { return info.lng }).sort(function(a,b){return a - b});
    but I am not sure what an IE7 fix would look like, if you have any suggestions please let me know, thanks!

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    The map method on arrays is a feature of JavaScript 1.6
    http://developer.mozilla.org/en/docs...ects:Array:map

    Internet Explorer only supports up to JavaScript 1.3
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the tips, Paul.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •