JavaScript - Google Maps Api, Javascript Problem With Pdf
Hi,
Not sure where to post this. I currently have a web app which utilises Google Maps & Directions, however some of these maps and directions will be used in pdf creation with tcpdf. The problem arises with the fact that tcpdf doesn't read javascript and therefore cant show the map. Any ideas on what I can do to compensate? Similar TutorialsHey all, I was wondering if someone would be able to help me with a problem I've been having. I'm attempting to find coordinates for several addresses at a time. I'm using a for-loop to loop through an array of addresses. I figured it would be best to have a separate function to evaluate the coordinate given an address, and just call it in every loop. Note that my code below is simplified (I removed the for loop because that's not where I'm having trouble). I know that the issue is probably because I'm trying to return a value from an anonymous function... I tried making the variable global, I tried having a return line from within the anonymous function, nothing has worked... any tips? Thanks -- Code follows Code: function initialize(){ var geocoder = new google.maps.Geocoder(); // creating a new geocode object var locCood = findcood('44106', geocoder); } function findcood(addr, geocoder) { var cood; if (geocoder) { geocoder.geocode({'address': addr}, function(results, status, cood){ if (status == google.maps.GeocoderStatus.OK) cood = results[0].geometry.location; else { cood = null; alert("Geocode was not successful for the following reason: " + status); } }); } else { alert("No Geocode"); cood = null; } alert(cood); return cood; } I have a working script and I want to add a toogleGroup command (which I have) to the end of the working script so that I can toggle map markers with radio buttons. Probably a simple addition. WORKING CODE: Code: //<![CDATA[ var iconPink = new GIcon(); iconPink.image = 'http://www.golfinggreys.com/img/ggmap_icon_attraction.png'; iconPink.shadow = ''; iconPink.iconSize = new GSize(24, 31); iconPink.shadowSize = new GSize(0, 0); iconPink.iconAnchor = new GPoint(11, 30); iconPink.infoWindowAnchor = new GPoint(5, 1); var iconOrange = new GIcon(); iconOrange.image = 'http://www.golfinggreys.com/img/ggmap_icon_accomm.png'; iconOrange.shadow = ''; iconOrange.iconSize = new GSize(24, 31); iconOrange.shadowSize = new GSize(0, 0); iconOrange.iconAnchor = new GPoint(11, 30); iconOrange.infoWindowAnchor = new GPoint(5, 1); var iconPurple = new GIcon(); iconPurple.image = 'http://www.golfinggreys.com/img/ggmap_icon_dining.png'; iconPurple.shadow = ''; iconPurple.iconSize = new GSize(24, 31); iconPurple.shadowSize = new GSize(0, 0); iconPurple.iconAnchor = new GPoint(11, 30); iconPurple.infoWindowAnchor = new GPoint(5, 1); var iconGreen = new GIcon(); iconGreen.image = 'http://www.golfinggreys.com/img/ggmap_icon_golf.png'; iconGreen.shadow = ''; iconGreen.iconSize = new GSize(24, 31); iconGreen.shadowSize = new GSize(0, 0); iconGreen.iconAnchor = new GPoint(11, 30); iconGreen.infoWindowAnchor = new GPoint(5, 1); var iconRed = new GIcon(); iconRed.image = 'http://www.golfinggreys.com/img/ggmap_icon_golfr.png'; iconRed.shadow = ''; iconRed.iconSize = new GSize(24, 31); iconRed.shadowSize = new GSize(0, 0); iconRed.iconAnchor = new GPoint(11, 30); iconRed.infoWindowAnchor = new GPoint(5, 1); var iconGrey = new GIcon(); iconGrey.image = 'http://www.golfinggreys.com/img/ggmap_icon_services.png'; iconGrey.shadow = ''; iconGrey.iconSize = new GSize(24, 31); iconGrey.shadowSize = new GSize(0, 0); iconGrey.iconAnchor = new GPoint(11, 30); iconGrey.infoWindowAnchor = new GPoint(5, 1); var iconBlue = new GIcon(); iconBlue.image = 'http://www.golfinggreys.com/img/ggmap_icon_shopping.png'; iconBlue.shadow = ''; iconBlue.iconSize = new GSize(24, 31); iconBlue.shadowSize = new GSize(0, 0); iconBlue.iconAnchor = new GPoint(11, 30); iconBlue.infoWindowAnchor = new GPoint(5, 1); var customIcons = []; customIcons["attraction"] = iconPink; customIcons["accomm"] = iconOrange; customIcons["dining"] = iconPurple; customIcons["golf"] = iconGreen; customIcons["golfr"] = iconRed; customIcons["services"] = iconGrey; customIcons["shopping"] = iconBlue; var markerGroups = { "attraction": [], "accomm": [], "dining": [], "golf": [], "golfr": [], "services": [], "shopping": []}; function load() { if (GBrowserIsCompatible()) { var i = 0; // Create the map // Make sure this element has the same ID as your div map = new GMap2(document.getElementById("googlemap")); // Add controls for moving and zooming the map. Use GSmallMapControl for small maps map.addControl(new GSmallMapControl()); // Add controls for switching between regular and satellite views map.addControl(new GMapTypeControl()); // Set the starting position and zoom level when the map loads map.setCenter(new GLatLng(51.920556,-103.798828), 7); // Read the data from XML var request = GXmlHttp.create(); // Open the XML file request.open("GET", "east_central.xml", true); request.onreadystatechange = function() { if (request.readyState == 4) { var xmlDoc = request.responseXML; // Obtain the array of markers and loop through it var markers = xmlDoc.documentElement.getElementsByTagName("marker"); for (var i = 0; i < markers.length; i++) { // Obtain the attribues of each marker var lat = parseFloat(markers[i].getAttribute("lat")); var lng = parseFloat(markers[i].getAttribute("lng")); var point = new GLatLng(lat,lng); var name = markers[i].getAttribute("name"); var phone = markers[i].getAttribute("phone"); var address = markers[i].getAttribute("address"); var city = markers[i].getAttribute("city"); var state = markers[i].getAttribute("state"); var url = markers[i].getAttribute("url"); var type = markers[i].getAttribute("type"); var marker = createMarker(point,name,phone,address,city,state,url,type); map.addOverlay(marker); } } } request.send(null); // Function to create the marker and set up the event window function createMarker(point,name,phone,address,city,state,url,type) { var marker = new GMarker(point, customIcons[type]); markerGroups[type].push(marker); var markerhtml = ""; if (name != "") markerhtml += "<b>" + name + "</b><br>"; markerhtml += address + ", " + city + ", " + state + "<br>"; if (phone != "") markerhtml += "p:" + phone + "<br>"; if (url != "") markerhtml += "<a href=\"" + url + "\">COURSE DETAILS</a>"; // Add a click event to each marker which will open the HTML window GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(markerhtml); }); i++; return marker; } } // Javascript alert for older browsers where Google Maps isn't supported else { alert("Sorry, the Google Maps API is not compatible with this browser"); } } //]]> THE ADDITION Code: function toggleGroup(type) { for (var i = 0; i < markerGroups[type].length; i++) { var marker = markerGroups[type][i]; if (marker.isHidden()) { marker.show(); } else { marker.hide(); } Just need to properly add that to the end. I am okay at editing and adapting codes, but I don't know the sytax. Tried JSLINT but still confused. Probably quite simple. Thanks hello all, what i would like to implement is the following : http://mon.grnet.gr/network/maps/lite/?load&ip but, the problem is that, although the numerical data that show the traffic volume passing through a link are available to me, i do not have clue on how i can display them onto the map ... ? i would be thankful, if you could give me a piece of advice. Hey Guys, I am building an application that uses Google Maps V3 and currently using JavaScript to show and hide markers. I have two check boxes, they have the same location but show if a user has been there or if they are going there. To hide the markers, I am doing the following function: Code: function hideMarker(location) { for (var i = 0; i < gmarkers.length; i++) { if (gmarkers[i].currentLocation == location) { gmarkers[i].setVisible(false); } } infowindow.close(); } Problem is, because two markers have the same location, it will hide both. I am passing a been and going value to gmarkers array (gmarkers[i].been etc) so wanted to say something like.. If been is unchecked only hide the been marker. Else if going is unchecked only hide the going marker. Else hide both markers. Anyone have any ideas how I can separate the been and going markers? I can't get my head around the logic Cheers. Hello chaps, I'm Nick I'm in the process of creating a web app using Google Maps. What the following code should do is retrieve some xml code from a page, then load it on to the map, using the geocoder to get lat/long values from the address. Most of it's just Google code I've mauled about with. The map loads, but none of the markers load on to the map. I've gone to the php page which generates the XML for the markers and all is fine there. I know the code is a messy crock of junk, I was sort of concentrating on trying to make it work then I'll sort out the nomenclature. Bad methodology, I know. Code: var id = null; var adress = null; var image = null; var point = null; var pointer = null; var geocoder = null; var iconBlue = new GIcon(); iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png'; iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'; iconBlue.iconSize = new GSize(12, 20); iconBlue.shadowSize = new GSize(22, 20); iconBlue.iconAnchor = new GPoint(6, 20); iconBlue.infoWindowAnchor = new GPoint(5, 1); var iconRed = new GIcon(); iconRed.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png'; iconRed.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'; iconRed.iconSize = new GSize(12, 20); iconRed.shadowSize = new GSize(22, 20); iconRed.iconAnchor = new GPoint(6, 20); iconRed.infoWindowAnchor = new GPoint(5, 1); var customIcons = []; customIcons["restaurant"] = iconBlue; customIcons["bar"] = iconRed; function load() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map")); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(52.2725, -0.8825), 12); geocoder = new GClientGeocoder(); GDownloadUrl("phpsqlajax_genxml3.php", function(data) { var xml = GXml.parse(data); var markers = xml.documentElement.getElementsByTagName("marker"); for (var i = 0; i < markers.length; i++) { id = markers[i].getAttribute("ID"); address = markers[i].getAttribute("ADDRESS"); image = markers[i].getAttribute("IMAGE"); var point3 = showAddress(address); var marker = createMarker(pointer, id, address, image); map.addOverlay(marker); } }); } } function showAddress(address) { point = geocoder.getLatLng(address,function(point) { if (!point) { alert(address + " not found"); } else { pointer = new GLatLng(point); return pointer; } }); } function createMarker(pointer, id, address, image) { var marker4 = new GMarker(pointer); var html = "<b>" + id + "</b> <br/>" + address + "</b> <br/>" + image; GEvent.addListener(marker, 'click', function() { marker4.openInfoWindowHtml(html); }); return marker4; } Thanks in advance Hello, I had this working in v2, but I'm migrating to v3 and I'm having some trouble with my sidebar. I think it might be variable scope problem, but I can't find the answer. I have a form which appends entries to an xml file, and my map script imports the xml to create markers and infowindows (all working). Functions to close the infowindow and recenter the map all work as well. It should also display a clickable sidebar with the names of the markers as links. It displays a side bar, but I only get one line which says 'undefined'. Here is my code: Code: var infowindow = new google.maps.InfoWindow(); var map = new google.maps.Map(); var side_bar_html = ""; var gmarkers = []; var shortname; var marker; function initialize() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","rp4.xml",false); xmlhttp.send(); xmlDoc = xmlhttp.responseXML; var markers = xmlDoc.getElementsByTagName("marker"); var point = new google.maps.LatLng(40.8068620, -96.6816790); var myOptions = { /* center: new google.maps.LatLng(40.8068620, -96.6816790), */ center: point, zoom: 4, mapTypeId: google.maps.MapTypeId.ROADMAP, /* mapTypeControl: True, mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU} */ }; // create the map map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); function bindInfoWindow(marker, map, infowindow, nfo) { google.maps.event.addListener(marker, 'click', function() { infowindow.close(); infowindow.setContent(nfo); infowindow.open(map, marker); map.panTo(marker.getPosition()); // map.setCenter(new google.maps.LatLng(lat,lng); map.setCenter(marker.getPosition()); }); } // document.getElementById("side_bar").innerHTML = side_bar_html; for (var i = 0;i<markers.length;i++) { var lat = parseFloat(markers[i].getAttribute("lat")); var lng = parseFloat(markers[i].getAttribute("lng")); point = new google.maps.LatLng(lat,lng); shortname = markers[i].getAttribute("company"); var company = markers[i].getElementsByTagName("company")[0].firstChild.nodeValue; var contact = markers[i].getElementsByTagName("contact")[0].firstChild.nodeValue; var str = markers[i].getElementsByTagName("str")[0].firstChild.nodeValue; var city = markers[i].getElementsByTagName("city")[0].firstChild.nodeValue; var phone = markers[i].getElementsByTagName("phone")[0].firstChild.nodeValue; var email = markers[i].getElementsByTagName("email")[0].firstChild.nodeValue; var web = markers[i].getElementsByTagName("web")[0].firstChild.nodeValue; var nfo = "<h1>"+company+"</h1>"+ "<p><b>"+company+"</b><br />"+ contact+"<br />"+ str+"<br />"+ city+"<br />"+ phone+"<br />"+ "<a href='mailto:"+email+"'>"+email+"</a></p>"+ "<a href='http://"+web+"'>"+web+"</a>"; marker = new google.maps.Marker({ position: point, map: map, title: company, clickable: true, }); marker.setMap(map); bindInfoWindow(marker, map, infowindow, nfo); } document.getElementById("side_bar").innerHTML = side_bar_html; } function myclick(k) { google.maps.event.trigger(gmarkers[k], "click"); // save the info we need to use later for the side_bar gmarkers.push(marker); // add a line to the side_bar html side_bar_html += '<a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + shortname + '<\/a><br>'; return marker; } Code: <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript"> var geocoder; var loc; geocoder = new google.maps.Geocoder(); var input = "32.83036,34.974339" var latlngStr = input.split(",",2); var lat = parseFloat(latlngStr[0]); var lng = parseFloat(latlngStr[1]); var latlng = new google.maps.LatLng(lat, lng); geocoder.geocode({'latLng': latlng}, function(results, status) { loc = results[1].formatted_address; }); </script> I need to use that var ("loc") in another place in my code, after the function finished running. I am not familiar with the Google Maps API, but reading through several tutorials and their documentation I have been able to create a basic version of what I need. It is simply a list of places to the right of the map, which can be clicked and will center the map on that location. However, I seem to be unable to use geocoding so that I can use addresses instead of latitude and longitudes. Here's what I have so far: http://www.mpapo.org/testzone/gmaps.html That is the functionality that I need, but I need to be able to use addresses instead of coordinates. I found this script from a tutorial: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>Google Maps JavaScript API Example</title> <script src="http://maps.google.com/maps?file=api&v=2&key=ADD_YOUR_KEY_HERE" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ var geocoder; var map; var restaurant = "The Old Mohawk Restaurant"; var address = "821 Mohawk Street, Columbus OH"; // On page load, call this function function load() { // Create new map object map = new GMap2(document.getElementById("map")); // Create new geocoding object geocoder = new GClientGeocoder(); // Retrieve location information, pass it to addToMap() geocoder.getLocations(address, addToMap); } // This function adds the point to the map function addToMap(response) { // Retrieve the object place = response.Placemark[0]; // Retrieve the latitude and longitude point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]); // Center the map on this point map.setCenter(point, 13); // Create a marker marker = new GMarker(point); // Add the marker to map map.addOverlay(marker); // Add address information to marker marker.openInfoWindowHtml(place.address); } //]]> </script> </head> <body onload="load()" onunload="GUnload()"> <div id="map" style="width: 400px; height: 300px"></div> </body> </html> And it works, but how would I integrate it with the other script? I have tried several times/ways but it always crashes. Any ideas? Firstly I know this is a PHP issue yet it is within javascript and IMO is the root cause of the problem. I'm trying to output markers from a search query of locations from my database, onto a Google Map (api v.3) using a tut I found http://tips4php.net/2010/10/use-php-...g-data-on-map/ When adding this to my page I'm getting Undefined index:errors. I have changed the variables in the php part of the script to suit my database yet have left everything else alone, cant figure out why I'm still getting a blank map???? Please help.... My code with errors being shown at bottom; Code: <script src="http://maps.google.com/maps/api/js?v=3&sensor=false" type="text/javascript"></script> <script type="text/javascript"> var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png", new google.maps.Size(32, 32), new google.maps.Point(0, 0), new google.maps.Point(16, 32)); var center = null; var map = null; var currentPopup; var bounds = new google.maps.LatLngBounds(); function addMarker(lat, lng, info) { var pt = new google.maps.LatLng(lat, lng); bounds.extend(pt); var marker = new google.maps.Marker({ position: pt, icon: icon, map: map }); var popup = new google.maps.InfoWindow({ content: info, maxWidth: 300 }); google.maps.event.addListener(marker, "click", function() { if (currentPopup != null) { currentPopup.close(); currentPopup = null; } popup.open(map, marker); currentPopup = popup; }); google.maps.event.addListener(popup, "closeclick", function() { map.panTo(center); currentPopup = null; }); } function initMap() { map = new google.maps.Map(document.getElementById("map"), { center: new google.maps.LatLng(0, 0), zoom: 14, mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControl: false, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR }, navigationControl: true, navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL } }); <br /> <b>Notice</b>: Undefined index: name in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>73</b><br /> <br /> <b>Notice</b>: Undefined index: lng in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>75</b><br /> <br /> <b>Notice</b>: Undefined index: info in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>76</b><br /> addMarker(53.994709, ,'<b></b><br/>'); <br /> <b>Notice</b>: Undefined index: name in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>73</b><br /> <br /> <b>Notice</b>: Undefined index: lng in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>75</b><br /> <br /> <b>Notice</b>: Undefined index: info in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>76</b><br /> addMarker(53.985416, ,'<b></b><br/>'); <br /> <b>Notice</b>: Undefined index: name in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>73</b><br /> <br /> <b>Notice</b>: Undefined index: lng in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>75</b><br /> <br /> <b>Notice</b>: Undefined index: info in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>76</b><br /> addMarker(53.985416, ,'<b></b><br/>'); <br /> <b>Notice</b>: Undefined index: name in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>73</b><br /> <br /> <b>Notice</b>: Undefined index: lng in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>75</b><br /> <br /> <b>Notice</b>: Undefined index: info in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>76</b><br /> addMarker(0.000000, ,'<b></b><br/>'); <br /> <b>Notice</b>: Undefined index: name in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>73</b><br /> <br /> <b>Notice</b>: Undefined index: lng in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>75</b><br /> <br /> <b>Notice</b>: Undefined index: info in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>76</b><br /> addMarker(0.000000, ,'<b></b><br/>'); center = bounds.getCenter(); map.fitBounds(bounds); } </script> I pulled this code from Google's example section to make markers on a v3 Google Maps API (I have added my own lat/long points and corresponding event listeners, of course, but this is still the spirit of the code):
Code: <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript"> var map; function initialize() { var map_center = new google.maps.LatLng(39.2,-84.479381); var store1 = new google.maps.LatLng(39.112456,-84.574779); var store2 = new google.maps.LatLng(39.314153,-84.261379); var store3 = new google.maps.LatLng(39.197099,-84.667579); var store4 = new google.maps.LatLng(39.16836,-84.479381); var myOptions = { zoom: 10, center: map_center, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var marker1 = new google.maps.Marker({ position: store1, map: map, title:"Store 1" }); var marker2 = new google.maps.Marker({ position: store2, map: map, title:"Store 2" }); var marker3 = new google.maps.Marker({ position: store3, map: map, title:"Store 3" }); var marker4 = new google.maps.Marker({ position: store4, map: map, title:"Store 4" }); google.maps.event.addListener(marker1, 'click', function() { map.set_center(store1); map.set_zoom(16); }); google.maps.event.addListener(marker2, 'click', function() { map.set_center(store2); map.set_zoom(16); }); google.maps.event.addListener(marker3, 'click', function() { map.set_center(store3); map.set_zoom(16); }); google.maps.event.addListener(marker4, 'click', function() { map.set_center(store4); map.set_zoom(16); }); } </script> This works without fail, but when I try to use a javascript array to hold my values and loop my way through the marker creation like so: Code: <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript"> var map; function initialize() { var map_center = new google.maps.LatLng(39.2,-84.479381); var store_locations = new Array(); var temporary_stuff = new Array(); store_locations[0] = "39.112456,-84.574779"; store_locations[1] = "39.314153,-84.261379"; store_locations[2] = "39.197099,-84.667579"; store_locations[3] = "39.16836,-84.479381"; var myOptions = { zoom: 10, center: map_center, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); for(i=0;i<store_locations.length;i++){ var marker_string = "position: "+new google.maps.LatLng(store_locations[i])+", map: map, title:\"Store "+(i+1)+"\";"; temporary_stuff[i] = new google.maps.Marker(marker_string); } var markers = new Array(); for(i=0;i<temporary_stuff.length;i++){ var the_marker = "position: temporary_stuff[" + i + "], map: map, title:\"Store " + (i+1) + "\";"; markers[i]= new google.maps.Marker(the_marker); } } </script> I get a blank map. Here's a link to the test file: http://rowsdower.freehostia.com/map_test.php It's not throwing up any errors in Firefox's developer or in IE but there it sits, a blank map. I'm sure this isn't clean or optimized code, but it looks correct to me. I've color-coded the code above to show what "for" loops are being used to try to replace which code. Hopefully that makes this more sensible. I haven't even tried to add the listeners yet since I can't get the markers to appear. Can anyone tell me why this isn't working or point me in a more productive direction? Is there a better way already out there that I haven't noticed? Hi, I'm not sure where I have translated this incorrectly. I have one google map embedded on my page which works fine. But I wanted to add a second one. I thought the easiest way to do this would be to have a second page which is called later on with all the details on it for the second map. However although I think (this I presume is where I went wrong) I have replicated the instructions correctly the place holder for the second map just remains blank. This is the code for my called page with the instructions for the second map: PHP Code: <?php echo $_POST['Map'] . '<br />'; ?> <div id="placemap_canvas"></div> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html {height:250px} body {height:250px} #placemap_canvas {width:100%; height:150px;} </style> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true" /> </script> <script type="text/javascript"> var latlng = new google.maps.LatLng ( <?php include("dbconnect.php"); $result = mysql_query("SELECT * FROM regions WHERE RegionPId='{$_POST['Map']}'"); while($row = mysql_fetch_array($result)){ echo $row['maplink']; } mysql_close($con); ?> ); var myOptions = { zoom: 4, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("placemap_canvas"), myOptions); } </script> And this is the script of the main page, just in case I would be better off keeping them both in one place. Code: <head> <script type="text/javascript"> function loadSubPlace(File,ID,Msg,Eile,EID,Esg){ loadXMLDoc1(File,ID,Msg); var mimer = setTimeout(function(){loadXMLDoc1(Eile,EID,Esg)},5000); } </script> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html {height:250px} body {height:250px} #map_canvas {width:30%; height:250px;} </style> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true" /> </script> <script type="text/javascript"> function initialize() { var latlng = new google.maps.LatLng ( <?php include("dbconnect.php"); $result = mysql_query("SELECT * FROM countries WHERE Country='{$_SESSION['Country']}'"); while($row = mysql_fetch_array($result)){ echo $row['Map']; } mysql_close($con); ?>); var myOptions = { zoom: 4, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } </script> </head> <body onload="initialize()"> <div class="countryright" id="map_canvas"> include("dbconnect.php"); $snowball=explode(';',$_POST['syringa']); $turnsol=$snowball[1]; $violet =$snowball[2]; $wakerobin=$snowball[3]; global $turnsol; global $violet; global $wakerobin; echo '<center><b><big>' . $wakerobin. '</big></b></center><br /><br />'; $result=mysql_query("SELECT * FROM regions WHERE country='{$turnsol}' AND region='{$violet}' AND place='{$wakerobin}' AND sub !='' ORDER BY sub ASC"); while($row = mysql_fetch_array($result)){ $wheat="{$row['RegionPId']};{$turnsol};{$violet};{$wakerobin};{$row['sub']}"; $tigerlilly=$row['RegionPId']; echo '<input type="button" class="button3" name="place" id="place" value="' . $row['sub'] . '" onclick="loadSubPlace(\'getPlace.php\',\'txtHintPlaceSub\',\'hepatica=' . urlencode($wheat) . '\',\'getPlaceMap.php\',\'placemapcanvas\',\'Map=' . urlencode($tigerlilly) . '\');" />'; } echo '<input type="button" class="button3" name="addplace" id="addplace" value="Add Place" onclick="loadXMLDoc1(\'getAddPlaceSub.php\',\'txtHintPlaceSub\', encodeURI(\'addsubplace=' . $_POST['syringa'] . '\'));" />'; echo '<br /><br /><div id="txtHintPlaceSub"></div><br /><br />'; mysql_close($con); ?> I've cut out the script that doesn't relate to this so I hope I haven't missed anything important. Hi I have just started looking at the Google maps, and have atutorial that will get the co-ordinates. What I want this to do, is then populate two fields on a form one called longitude and one called latitude Code: function usePointFromPostcode(postcode, callbackFunction) { localSearch.setSearchCompleteCallback(null, function() { if (localSearch.results[0]) { var resultLat = localSearch.results[0].lat; var resultLng = localSearch.results[0].lng; var point = new GLatLng(resultLat,resultLng); callbackFunction(point); }else{ alert("Postcode not found!"); } }); localSearch.execute(postcode + ", UK"); } Any ideas/tips would be be much appreciated I have some problems with intergrating google maps into my page I cant seem to get a marker to appear on my map. I have tried numerous methods but non seem to work. I have integrated the google maps on my main site, repositioned and re-sized. The code below is a test page i work on to get code to work. It's just a map on a page entire code: <!DOCTYPE HTML> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 25px; padding: 25px } #map_canvas { height: 100% } </style> <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDrxZnpYBNIwzBFVYaDY__BMONEjNEGZaI&sensor=false"> </script> <script type="text/javascript"> function initialize() { var myLatlng = new google.maps.LatLng(-25.363882,131.044922); var myOptions = { zoom: 4, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);} var marker = new google.maps.Marker({ position: myLatlng, map: map, title:"Hello World!" }); </script> </head> <body onload="initialize()"> <div id="map_canvas" style="width:100%; height:100%"></div> </body> </html> can anybody tell my where i am going wrong and just the map appears with no marker? thanks I am using jMapping(http://vigetlabs.github.com/jmapping/) for using jQuery with google maps. What I'm trying to do is add an event listener so that when you click on a marker it will call a function I made within the jMapping function. Does anyone have any clues? everything I've tried doesn't work.
I'm completely at a loss how to embed a map with the new google maps api setup. I found a snippet of code that I dropped in with some small database variables pulled in and was done. Then an error came that the API was no good. So I went in and set up an anaccount, got an api and now I just simply have no clue what their instructions are saying I need to do. Gah! Here's what I originally had: I now have a Client ID, client secret and stuff. But no clue how to set up this url, etc. Code: </script> <script src="//maps.google.com/maps?file=api&v=2&key=AIzaSyD4iE2xVSpkLLOXoyqT-RuPwURN3ddScAI" type="text/javascript"></script> <script type="text/javascript"> function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(<?php echo $c_row['location_longitude']; ?>,<?php echo $c_row['location_latitude']; ?>), 13); // Add the latitude/longitude marker to the map var point = new GLatLng(<?php echo $c_row['location_longitude']; ?>,<?php echo $c_row['location_latitude']; ?>); map.addOverlay(new GMarker(point)); map.setUIToDefault(); } } </script> <b>Map:<br><br><div id="map_canvas" style="width: 500px; height: 300px; z-index:4000;border-width:medium;border-color:#030;"></div></b> Hey I'm quite new at javascript and am currently in the process of creating a site that embeds google maps using an xml document. What I'm trying to do is categories the markers on my map. I am trying to make it so there are check boxes at the bottom and when i check the boxes, i.e. theatres, the markers will appear for the theatres and disappear when unchecked. Using some example code i have modified, i have so far got the maps to pickup the markers from the xml with the check boxes but the markers are all just on the page and the check boxes dont do anything and I am stuck as to of why. here's my code: Code: <!DOCTYPE HTML> <html> <head> <title>Google Maps</title> <script src="mykey"></script> </head> <body style="margin:0px; padding:0px;" onload="initialize()"> <table border=1> <tr> <td> <div id="map" style="width: 550px; height: 450px"></div> </td> <td valign="top" style="width:150px; text-decoration: underline; color: #4444ff;"> <div id="side_bar"></div> </td> </tr> </table> <form action="#"> Theatres: <input type="checkbox" id="theatrebox" onclick="boxclick(this,'theatre')" /> Golf Courses: <input type="checkbox" id="golfbox" onclick="boxclick(this,'golf')" /> Tourist Information: <input type="checkbox" id="infobox" onclick="boxclick(this,'info')" /><br /> </form> <script type="text/javascript"> _uacct = "UA-162157-1"; urchinTracker(); </script> </body> <script type="text/javascript"> //<![CDATA[ if (GBrowserIsCompatible()) { var side_bar_html = ""; var gmarkers = []; var map = null; function createMarker(point,name,html,category) { var marker = new GMarker(point); GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); }); marker.mycategory = category; marker.myname = name; gmarkers.push(marker); side_bar_html += '<a href="javascript<b></b>:myclick(' + (gmarkers.length-1) + ')">' + name + '<\/a><br>'; return marker; } function show(category) { for (var i=0; i<gmarkers.length; i++) { if (gmarkers[i].mycategory == category) { gmarkers[i].setVisible(true); } } document.getElementById(category+"box").checked = true; } ensures the checkbox is cleared == function hide(category) { for (var i=0; i<gmarkers.length; i++) { if (gmarkers[i].mycategory == category) { gmarkers[i].setVisible(false); } } document.getElementById(category+"box").checked = false; that we just hid infowindow.close(); } function boxclick(box,category) { if (box.checked) { show(category); } else { hide(category); } makeSidebar(); } function myclick(i) { google.maps.event.trigger(gmarkers[i],"click"); } var map = new GMap2(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng( 53.8363,-3.03771), 11); GDownloadUrl("categories.xml", function(doc) { var xmlDoc = GXml.parse(doc); var markers = xmlDoc.documentElement.getElementsByTagName("marker"); for (var i = 0; i < markers.length; i++) { // obtain the attribues of each marker var lat = parseFloat(markers[i].getAttribute("lat")); var lng = parseFloat(markers[i].getAttribute("lng")); var point = new google.maps.LatLng(lat,lng); var address = markers[i].getAttribute("address"); var name = markers[i].getAttribute("name"); var html = "<b>"+name+"<\/b><p>"+address; var category = markers[i].getAttribute("category"); // create the marker var marker = createMarker(point,name,html,category); map.addOverlay(marker); } document.getElementById("side_bar").innerHTML = side_bar_html; show("theatre"); hide("golf"); hide("info"); }); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } </script> </body> </html> If anybody help with this and tell me where I am going wrong, it would be much appreciated. thanks Hey all I'm quite a newbie at javascript and I'm trying to have links to google maps markers. I have a page with my embeded google maps on it and some markers. What I'm basically looking to do is have a web page with a menu down the side and when you click the menu items, the google maps markers would pop up on the map. For example, city attractions down a side menu and when you click say restaurants, the markers would pop up the location restaurants in a certain place, then you could click pubs and the restaurant markers would dissapear and the pub markers would appear. Can anyboy help me with this or even direct me to some code that would help. Thanks all. Hello! I'm developing a small application with Google Maps API for use in Wordpress and didn't want to place all the javascript into the Worpress page template file. But whenever I place the javascript that works fine in page tempalte into separate javascript file in Wordpress, all of the code using Google Maps API except the code that runs Maps itself stops working. So the Maps runs but for example Geocoder does not. I'm simulatenously using Google's jQuery API. I hope someone has experience with this and can help me. I'm trying to make a map that will show your current location, but also load an xml file to show certain attractions in your area. I have the code to work for getting your current location, but I can't figure out how to implement loading the xml file and placing markers based off of that xml file. Here is the code for getting my location: Code: function show_position(p) { document.getElementById('current').innerHTML="latitude="+p.coords.latitude.toFixed(2)+" longitude="+p.coords.longitude.toFixed(2); var pos=new google.maps.LatLng(p.coords.latitude,p.coords.longitude); map.setCenter(pos); map.setZoom(14); var infowindow = new google.maps.InfoWindow({ content: "<strong>yes</strong>" }); var marker = new google.maps.Marker({ position: pos, map: map, title:"You are here" }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); }); } </script > Can anybody help me figure this out? Thank you in advance |