Guus, First, you may want to read about the suggested posting guidelines at the following URL http://groups.google.com/group/Google-Maps-API/web/suggested-posting-guidelines
It doesn't help to post all the javascript and code within a message, just a URL to your app... You may want to keep this in mind in future posts... Also, looking at your code, the problem seems to be that you are in- lining your initialization to the map. Consider these two lines of your code: GMap2.prototype.showBounds = function(bounds_, opt_options){ and later, var map = new GMap2(document.getElementById("map")); the problem you are having is that the google maps loads in at least two different js files and it can take up to 2 or 3 seconds for hte entire API to download to the browser. Therefore, before you alter the GMap2 prototype or initialize a new GMap2, you need to first ensure that your maps have loaded. There are two ways to accomplish this: 1) set your body tag onload event handler to point to a function that initializes your maps and alters the prototype or 2) better yet, use Google.Load to load your maps and set the onCallback function to run your initialization. This question has also been asked on other threads...if you want to search for those other converstations that reference this topic, just search the newsgroup: http://groups.google.com/group/Google-Maps-API/search?group=Google-Maps-API&q=a+is+undefined&qt_g=Search+this+group good luck, hope this helps :) On Jul 19, 1:06 pm, Guus Jansen <guus.jan...@freeler.nl> wrote: > Since 10-07-2009 (nothing changed in my coding) my sitewww.jade1.nl > gives no longer errorfree Gmap2-pages: (on start page click on the > link : > > "Voorbeeld: Een fietstocht" > > From Firefox errorconsole(Firebug) I get: > Error: a is undefined (11 times for every mouse movement on the map) > Source:http://maps.gstatic.com/intl/nl_ALL/mapfiles/140g/maps2.api/main.js > Line: 480 > > That line is: > Pg.prototype=new Vk;Pg.prototype.fromLatLngToPixel=function(a,b){var > c=this,d=c.Fx[b],e=z(d.x+a.lng()*c.Hx[b]),f=Pd(Math.sin(re(a.lat > ())),-0.9999,0.9999),g=z(d.y+0.5*Math.log((1+f)/(1-f))*-c.Ix > [b]);return new L(e,g)}; > > Can anyone help me solve the problem? > > I use Javascript code for a sidebar and maybe there is an error in > that code: > > member fu_map_sb.js: > //denk erom de positie van de sidebar(novel) en de map zijn relatief > gekoppeld, er wordt van alles opnieuw geplaatst. > //****eerst de breedte van de hele sidebar: > var sblockwidth= 365 ;//de breedte is direct aanpasbaar > var sblockwidthp= sblockwidth + 50 ;//inclusief padding > var newcontrol= sblockwidth + 10;//nieuwe Gcontrol vlak naast zijbalk > var lbarwidth= "100" ;// geen invloed te zien > //nog px toevoegen: > /** > * A general helper function for creating html elements. <div> as > default element type > * @author Esa 2008 > * used for infowindows and sidebar > */ > function createElem(opt_className, opt_html, opt_tagName) { > var tag = opt_tagName||"div"; > var elem = document.createElement(tag); > if (opt_html) elem.innerHTML = opt_html; > if (opt_className) elem.className = opt_className; > return elem; > > } > > /** > * Sidebar <div> made a GControl() > * @author Esa 2008 > */ > function sideBlockControl(opt_options){ > this.opts = opt_options||{};} > > sideBlockControl.prototype = new GControl(); > sideBlockControl.prototype.initialize = function(_map) { > var openText = this.opts.openText||"Positie-balk"; > var opener = createElem("sideblock-open",openText); // open button > opener.style.border = "1px solid black"; > opener.style.textAlign = "center"; > opener.style.fontSize = "12px"; > opener.style.fontWeight= "bold"; > opener.style.fontFamily = "Arial"; > opener.style.backgroundColor = "#0000ff"; > opener.style.color = "#ffffff"; > opener.style.width = "65px"; > opener.style.position = "relative"; > opener.style.top = "7px"; > opener.style.left = "63px"; > opener.style.cursor = "pointer"; > _map.getContainer().appendChild(opener); > var header = createElem("sideblock-header"); // header containing > close button > header.style.textAlign = "left"; > > var closeText = this.opts.closeText||" <div align='left' > float='left' style='background-color:blue; border: 2px solid silver;'> > <font style='color:white' size=2 > <b>Positiebalk > Sluit > de zijbalk: <input type=button style='background-color:red' > value='X' /></b></font></div><br /> "; > var close = createElem("sideblock-close",closeText,"span"); // close > button > close.style.cursor = "pointer"; > header.appendChild(close); > var leftBar = createElem("sideblock"); // the parent element of the > sidebar > leftBar.appendChild(header); > _map.getContainer().appendChild(leftBar); > leftBar.style.width = this.opts.sideBlockWidth||lbarwidth; > leftBar.style.height = "96%"; > var contents = createElem("sideblock-container"); //contents div > leftBar.appendChild(contents); > contents.style.height = "95%"; > contents.style.overflow = "auto"; > var me = this; > me.container = contents; > me.isVisible = true; > function openEvent(){me.isVisible=true; GEvent.trigger > (me,'open',true)}; > function closeEvent(){me.isVisible=false; GEvent.trigger > (me,'close',false)}; > me.show = function(){leftBar.style.display = "block"; openEvent()}; > me.hide = function(){leftBar.style.display = "none"; closeEvent()}; > close.onclick = function(){me.hide()}; > opener.onclick = function(){me.show()}; > return leftBar;} > > sideBlockControl.prototype.getDefaultPosition = function() { > return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10, 20)); > > } > > /** > * Google logo made a GControl() > */ > function PowerLogo(){}; > PowerLogo.prototype = new GControl(); > PowerLogo.prototype.initialize = function(map) { > var logo = document.createElement("img"); > map.getContainer().appendChild(logo); > logo.src = "http://maps.google.com/intl/fi_ALL/mapfiles/ > poweredby.png"; > return logo;} > > PowerLogo.prototype.getDefaultPosition = function() { > return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize > (newcontrol,7)); > > } > > /** > * A GLargeMapControl with adjusted default position > */ > function OffsetControl(){}; > OffsetControl.prototype = new GLargeMapControl(); > OffsetControl.prototype.getDefaultPosition = function() { > return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(newcontrol, > 7)); > > } > > /** > * GMap2.showBounds() method. Fit bounds to viewport with paddings. > * @ author Esa 2008 > * @ param bounds_ GLatLngBounds() > * @ param opt_options Optional options object {top, right, bottom, > left, save} > */ > GMap2.prototype.showBounds = function(bounds_, opt_options){ > var opts = opt_options||{}; > opts.top = opts.top*1||0; > opts.left = opts.left*1||0; > opts.bottom = opts.bottom*1||0; > opts.right = opts.right*1||0; > opts.save = opts.save||true; > opts.disableSetCenter = opts.disableSetCenter||false; > var ty = this.getCurrentMapType(); > var port = this.getSize(); > if(!opts.disableSetCenter){ > var virtualPort = new GSize(port.width - opts.left - opts.right, > port.height - opts.top - opts.bottom); > this.setZoom(ty.getBoundsZoomLevel(bounds_, virtualPort)); > var xOffs = (opts.left - opts.right)/2; > var yOffs = (opts.top - opts.bottom)/2; > var bPxCenter = this.fromLatLngToDivPixel(bounds_.getCenter()); > var newCenter = this.fromDivPixelToLatLng(new GPoint(bPxCenter.x- > xOffs, bPxCenter.y-yOffs)); > this.setCenter(newCenter); > if(opts.save)this.savePosition(); > } > var portBounds = new GLatLngBounds(); > portBounds.extend(this.fromContainerPixelToLatLng(new GPoint > (opts.left, port.height-opts.bottom))); > portBounds.extend(this.fromContainerPixelToLatLng(new GPoint > (port.width-opts.right, opts.top))); > return portBounds; > > } > > /** > * Map > */ > _mPreferMetric=true; > var blueIcon = new GIcon(G_DEFAULT_ICON); > blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/ > blue-dot.png"; > blueIcon.iconSize = new GSize(25, 25); > > var greenIcon = new GIcon(G_DEFAULT_ICON); > greenIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/ > green-dot.png"; > greenIcon.iconSize = new GSize(25, 25); > > var yellIcon = new GIcon(G_DEFAULT_ICON); > yellIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/ > yellow-dot.png"; > yellIcon.iconSize = new GSize(25, 25); > > var ZIcon = new GIcon(G_DEFAULT_ICON); > ZIcon.image = "http://www.google.com/mapfiles/markerZ.png"; > ZIcon.iconSize = new GSize(15, 25); > > var RIcon = new GIcon(G_DEFAULT_ICON); > RIcon.image = "http://www.google.com/mapfiles/markerR.png"; > RIcon.iconSize = new GSize(15, 25); > > var smicon = new GIcon(); > smicon.image = "http://labs.google.com/ridefinder/images/ > mm_20_yellow.png"; > smicon.shadow = "http://labs.google.com/ridefinder/images/ > mm_20_shadow.png"; > smicon.iconSize = new GSize(15, 25); > smicon.shadowSize = new GSize(22, 20); > smicon.iconAnchor = new GPoint(6, 20); > smicon.infoWindowAnchor = new GPoint(5, 1); > > var map = new GMap2(document.getElementById("map")); > var Lpos = new GLatLng(stLat[stLat.length-1], stLon[stLon.length-1]); > map.setCenter(Lpos, Mzoomst, G_HYBRID_MAP);// map must be first > setCentered. Then virtualCenter function works. > var shiftedLpos = virtualCenter(Lpos, -sblockwidthp); > map.setCenter(shiftedLpos, Mzoomst); // Recentering to small viewport > map.addControl(new GLargeMapControl()); > map.addControl(new GMapTypeControl()); > map.addMapType(G_PHYSICAL_MAP); > map.enableContinuousZoom(); > map.enableScrollWheelZoom(); > var scalePos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize > (475,7)); > map.addControl(new GScaleControl(256), scalePos); > new GKeyboardHandler(map); > var mapContainer = document.getElementById("map_canvas"); > GEvent.trigger(document, "click", {srcElement: mapContainer, > target: > mapContainer, nodeType: 1}); > > var overv = new GOverviewMapControl(); > map.addControl(overv); > overv.hide(1); > map.openInfoWindowHtml(map.getCenter(),"Nice to see you."); > map.closeInfoWindow(); //preloading infowindow > document.getElementById("api-v").innerHTML = 'api v2.'+G_API_VERSION; > map.clearOverlays(); > > //zie voor kleurenschema reisd_incl1, vervoermiddel afhankelijk. > var myroute = new GPolyline([],"#ff4500", 6, .5); > map.addOverlay(myroute); > var mysroute = new GPolyline([],"#ff00ff", 6, .5); > map.addOverlay(mysroute); > > //myroute.enableDrawing(options); > var center = new GLatLng(47.4153, 13.6385); > //nog uitzoeken wat het verschil is tussen click en rightclick. > // nog uitzoeken wat de Gmap2 commands zijn > /* > > GEvent.addListener( map, "rightclick", function() { > if ( map.getZoom() <= 16 ) > map.setCenter( p.scaleRelative( map.getCenterLatLng(), -1 ), > map.getZoom() + 1 ); > alert ("wilt u hier een punt tussenvoegen?"); > }); > */ > > Mtype=map.getCurrentMapType(); > map.disableDoubleClickZoom(); > GEvent.addListener(map, 'dblclick', mapClick); > GEvent.addListener(map, 'infowindowclose', mapIWClose); > /* > GEvent.addListener( map, "click", function(o,p) { > alert ("wilt u hier een punt tussenvoegen?"); > if ( o != null ) return; > if ( map.getZoomLevel() > 1 ) > map.centerAndZoom( p, map.getZoom() - 2 ); > else if ( map.getZoom() == 1 ) > map.centerAndZoom( p, 0 );}); > > */ > > function mapClick(overlay,point) { > Mtype=map.getCurrentMapType(); > Mzoom= map.getZoom(); > //alert('testen--in mapclick'); > > //alert ("was er een remove: " + markremoved); > tit= 'Dit is een zelfgecreerde Marker op: ' + point.lat().toFixed(6) > + ', ' + point.lng().toFixed(6) ; > tinr= -1; > //alert('titel en nr: ' + tit + ',' + tinr); > if (point) { > if (markremoved != "yes") addEMarker(point, tit ,tinr, 'naam > ?' ); > else markremoved = ""; > //** helaas deze poging zoom te voorkomen of op te heffen werkt niet, > het centreren wel. > // if ( map.getZoom() >= 2 ) { > // map.setCenter(point,map.getZoom() - 1 ); > // } > map.setCenter(point,Mzoom,Mtype); > } > } > > function Bepindex(mapPt,selmarki) { > selmarki= -1; > var shdst= 9999999999999.0; > var dst= 0; > var aantmark= MarkArr.length-1; > var arrpt; > for (var k = aantmark; k>=0; k--) { > if (MarkArr[k]!=null){ > arrpt = MarkArr[k].getPoint(); > dst=distP2P(arrpt,mapPt); > if (dst < shdst) { > shdst= dst; > if (shdst < 20) selmarki=k; > } > } > } > return selmarki; > > } > > function distP2P(P, Q){ > dx = P.x - Q.x; > dy = P.y - Q.y; > > var dst = Math.sqrt(dx * dx + dy * dy); > return dst; > > } > > function markerDragEnd() { > GEvent.trigger(this,'click'); > > } > > function miniMapZoomEnd(oldZ,newZ) { > showMinimapRect(this); > > } > > function miniMapMoveEnd() { > showMinimapRect(this); > > } > > function showMinimapRect(detailMap) { > if (rect) { > map.removeOverlay(rect); > } > var bounds = detailMap.getBounds(); > var polyPoints = [ bounds.getSouthWest(), > new > GLatLng(bounds.getSouthWest().lat(),bounds.getNorthEast().lng > ()), > bounds.getNorthEast(), > new > GLatLng(bounds.getNorthEast().lat(),bounds.getSouthWest().lng > ()), > bounds.getSouthWest() > ] > > rect = new GPolygon(polyPoints, '#ff0000', 1, 1, '#ff0000', 0.3); > map.addOverlay(rect); > > } > > function mapIWClose() { > if (rect) { > map.removeOverlay(rect); > } > if (emrect) { > map.removeOverlay(emrect); > } > if (smrect) { > map.removeOverlay(smrect); > } > > } > > /** > * 7 random markers > */ > function randomMarkers(_bounds){ > var bounds = _bounds||map.getBounds(); > var markerBounds = new GLatLngBounds(); > var span = bounds.toSpan(); > var southWest = bounds.getSouthWest(); > var northEast = bounds.getNorthEast(); > map.clearOverlays(); > for (var i=0; i<7; i++){ > var point = new GLatLng(southWest.lat() + span.lat() * Math.random > ()*0.9, > southWest.lng() + span.lng() * Math.random > ()*0.9); > var marker = (new GMarker(point)); > map.addOverlay(marker); > marker.bindInfoWindowHtml('<b>'+i+'</b>'); > markerBounds.extend(point); > } > fit(markerBounds); > > } > > /** > * Pan and zoom to fit calling GMap.showBounds > */ > function fit(bounds){ > var opts = {top:40,right:10,bottom:5,left:50}; > if(myBlock.isVisible)opts.left = sblockwidthp; //sideBlock width > +padding > map.showBounds(bounds, opts); > > } > > /** > * SideBlock > */ > var sideOptions = {sideBlockWidth:sblockwidth+'px'}; > var myBlock = new sideBlockControl(sideOptions); > map.addControl(myBlock); > > var midLogo = new PowerLogo(); > var midControl = new OffsetControl(); > > GEvent.addListener(myBlock, 'open', function(){ > map.addControl(midLogo); > map.addControl(midControl); > refocus();}); > > GEvent.addListener(myBlock, 'close', function(){ > map.removeControl(midLogo); > map.removeControl(midControl); > refocus(); > > }); > > /** > * Calculating zoom focus point > */ > function virtualCenter(point, xOffs){ > var pixCenter = map.fromLatLngToDivPixel(point); > var virtualPxCenter = new GPoint(pixCenter.x + xOffs/2, > pixCenter.y); > return map.fromDivPixelToLatLng(virtualPxCenter);} > > function refocus(){ > if(myBlock.isVisible) > { > var pnt = virtualCenter(map.getCenter(),sblockwidth);//sideBlock > width > map.setFocus(pnt); > }else{ > map.setFocus(); //reset > }} > > GEvent.addListener(map,"moveend",function(){ > refocus(); > > }); > > /** > * doubleClickZoom recentering > */ > GEvent.addDomListener(map,"dblclick",function(a,b){ > var pnt = virtualCenter(b, -sblockwidth); //sideBlock width > if(myBlock.isVisible)map.setCenter(pnt); > > }); > > /** > * On load > */ > myBlock.container.appendChild(document.getElementById("novel")); > myBlock.show(); > if(window.innerWidth<300)myBlock.hide(); > > window.onload = function(){ > } > > /** Hacked function because GMAPS does not give us > * a fromLatLngToContainerPixel. Cheers sde for the > * firstChild.firstChild find. > * > * @param {GLatLng} glalo > * > * @returns A GPoint specifying GLatLng translated into "Container" > * coordinates 208 * @type GPoint > */ > function fromLatLngToContainerPixel(glalo) { > // first we translate into "DivPixel" > var gPoint = map.fromLatLngToDivPixel(glalo); > // locate the sliding "Div" div > var div = this.b.firstChild.firstChild; > // adjust by the offset of "Div" and voila! > gPoint.x += div.offsetLeft; > gPoint.y += div.offsetTop; > return gPoint;} > > //******************** > function routeMarkers(_bounds){ > //******************** > > var bounds = _bounds||map.getBounds(); > var markerBounds = new GLatLngBounds(); > var span = bounds.toSpan(); > var southWest = bounds.getSouthWest(); > var northEast = bounds.getNorthEast(); > //map.clearOverlays(); > map.disableDoubleClickZoom(); > tinr= -1; > for (var i=0; i<RstLat.length; i++){ > var smpoint = new GLatLng(RstLat[i],RstLon[i]); > // tit= 'Dit is een zelfgecreerde Marker op: ' + stLat[i].toFixed(6) > + ', ' + stLon[i].toFixed(6) ; > tit= 'Via systeem gegenereerde Marker op: ' + RstLat[i] + ', ' + > RstLon[i] ; > // alert('titel en nr: ' + tit + ',' + tinr); > if (smpoint) { > map.setCenter(smpoint,Mzoom,Mtype); > addSMarker(smpoint, tit , tinr, RstPlaats[i]); > } > markerBounds.extend(smpoint); > } > fit(markerBounds); > > } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Maps API" group. To post to this group, send email to Google-Maps-API@googlegroups.com To unsubscribe from this group, send email to google-maps-api+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Maps-API?hl=en -~----------~----~----~----~------~----~------~--~---