laPistola Posted June 16, 2009 Share Posted June 16, 2009 This script worked fine right up to the point i added the lines marked with comments // This The script is: <script type="text/javascript"> function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(53.4989705,-2.1118907), 13); var bounds = new GLatLngBounds(); function zoomfit() { // This Function newzoom = getBoundsZoomLevel(bounds); newcenter = bounds.getCenter(); map.setCenter (newcenter,newzoom); } var location = new GLatLng(53.4989705,-2.1118907); var marker = new GMarker(location); marker.value = 1; GEvent.addListener(marker, "click", function() { var myHtml = "<b>#" + "1" + "</b><br/>" + "Your search location"; map.openInfoWindowHtml(location, myHtml); }); map.addOverlay(marker); map.addOverlay(createMarker(new GLatLng(53.5390200,-2.1297100),2,"Booth House")); map.addOverlay(createMarker(new GLatLng(53.7462530,-1.5942410),3,"City Mills")); function createMarker(point, number, message) { var marker = new GMarker(point); marker.value = number; GEvent.addListener(marker, "click", function() { var myHtml = "<b>#" + number + "</b><br/>" + message; map.openInfoWindowHtml(point, myHtml); }); bounds.extend(point); // This zoomfit(); // This return marker; } map.setUIToDefault(); } } </script> When the pages loads the map loads but without the controls, only showing the one marker, as well as the status displays error on page. When i remove bounds.extend(point); // This zoomfit(); // This The script works fine again with no errors Any ideas on how to can get this working? Thank you in advanced Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted June 16, 2009 Share Posted June 16, 2009 Function statements cannot be placed in blocks. Use a function expression or move the statement to the top of the outer function. Quote Link to comment Share on other sites More sharing options...
laPistola Posted June 16, 2009 Author Share Posted June 16, 2009 Thank you for the reply but i dont quite get what you mean, i have moved the zoomfit function out side of the main function but same errors. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted June 17, 2009 Share Posted June 17, 2009 A return statement can only be used inside a function or constructor. The return statement cannot have an expression if used inside a constructor or a setter. Quote Link to comment Share on other sites More sharing options...
laPistola Posted June 17, 2009 Author Share Posted June 17, 2009 Thank you but im still confused to what your getting at sorry. The return marker; works fine i only get errors when i add the lines below bounds.extend(point); zoomfit(); from what you said i gathered i had to move the above code from that function, this is what i have now but still i have no controls on the map nor is it showing the 2 markers <script type="text/javascript"> function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(53.4989705,-2.1118907), 13); var bounds = new GLatLngBounds(); function zoomfit() { newzoom = getBoundsZoomLevel(bounds); newcenter = bounds.getCenter(); map.setCenter (newcenter,newzoom); } var location = new GLatLng(53.4989705,-2.1118907); var marker = new GMarker(location); marker.value = 1; GEvent.addListener(marker, "click", function() { var myHtml = "<b>#" + "1" + "</b><br/>" + "Your search location"; map.openInfoWindowHtml(location, myHtml); }); map.addOverlay(marker); var location2 = new GLatLng(53.5390200,-2.1297100); map.addOverlay(createMarker(location2,2,"Booth House ")); bounds.extend(location2); zoomfit(); map.addOverlay(createMarker(new GLatLng(53.7462530,-1.5942410),3,"City Mills ")); function createMarker(point, number, message) { var marker = new GMarker(point); marker.value = number; GEvent.addListener(marker, "click", function() { var myHtml = "<b>#" + number + "</b><br/>" + message; map.openInfoWindowHtml(point, myHtml); }); return marker; } map.setUIToDefault(); } } </script> Quote Link to comment Share on other sites More sharing options...
laPistola Posted June 17, 2009 Author Share Posted June 17, 2009 i now have <script type="text/javascript"> function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(53.4989705,-2.1118907), 13); var bounds = new GLatLngBounds(); var location = new GLatLng(53.4989705,-2.1118907); var marker = new GMarker(location); marker.value = 1; GEvent.addListener(marker, "click", function() { var myHtml = "<b>#" + "1" + "</b><br/>" + "Your search location"; map.openInfoWindowHtml(location, myHtml); }); map.addOverlay(marker); bounds.extend(location); var location2 = new GLatLng(53.5390200,-2.1297100); createMarker(location2,2,"Booth House "); bounds.extend(location2); createMarker(new GLatLng(53.7462530,-1.5942410),3,"City Mills "); function createMarker(point, number, message) { var marker = new GMarker(point); marker.value = number; GEvent.addListener(marker, "click", function() { var myHtml = "<b>#" + number + "</b><br/>" + message; map.openInfoWindowHtml(point, myHtml); }); map.addOverlay(marker); } map.setUIToDefault(); zoomfit(); function zoomfit() { newzoom = getBoundsZoomLevel(bounds); newcenter = bounds.getCenter(); map.setCenter (newcenter,newzoom); } } } </script> which has fixed the controls but still its only zooming to the one marker?? Quote Link to comment Share on other sites More sharing options...
laPistola Posted June 20, 2009 Author Share Posted June 20, 2009 i still havent got this working. could anyone explain or show an example please. Thank you! Quote Link to comment Share on other sites More sharing options...
laPistola Posted June 23, 2009 Author Share Posted June 23, 2009 Please anyone, i do help out here when i can and i really need this working Thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.