suess0r Posted January 17, 2007 Share Posted January 17, 2007 hi, I have my google map api creating the map I want for an individual location. But i have a site with over 500 locations and I would like to create the maps for each individual location on the fly. I have the $address, $city, and $state fields in my database, and was wondering if i could POST those somehow to a geocoder script of some sort, or some other way of generating the Lat/Long??Here's my code for the map and the XML file for the marker, thanks![quote]<!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</title> <!--insert your API key after key= --> <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAOKTLdFzzugf9e0CcpLMxOBRYEEkl04RzaEe06qoUTiRHazMqAhQh_L_buTd6bwYDCrPqvHpnFt8C-w" type="text/javascript"></script> </head> <!--note the onunload event attached to the body tag--> <body onunload="GUnload()"> <!--this Div holds the map--> <!--change the style to fit your needs--> <div id="map" style="width: 550px; height: 450px; border: 1px solid #000000;"></div> <!--What to display if JavaScript is disabled in the user's browser--> <noscript><strong>JavaScript must be enabled in order for you to use Google Maps.</strong><br /> However, it seems JavaScript is either disabled or not supported by your browser. <br /> To view Google Maps, enable JavaScript by changing your browser options, and then try again.<br /><br /> </noscript> <script type="text/javascript"> //<![CDATA[ if (GBrowserIsCompatible()) { // this variable will collect the html which will eventually be placed in the GMapSidebar var GMapSidebar_html = ""; // arrays to hold copies of the markers and html used by the GMapSidebar // because the function closure trick doesnt work there var gmarkers = []; var htmls = []; var i = 0; // arrays to hold variants of the info window html with get direction forms open var to_htmls = []; var from_htmls = []; // A function to create the marker and set up the event window function createMarker(point,name,html) { var marker = new GMarker(point); // The info window version with the "to here" form open to_htmls[i] = html + '<br>Directions: <b>To here</b> - <a href="javascript:fromhere(' + i + ')">From here</a>' + '<br>Start address:<form action="http://maps.google.com/maps" method="get" target="_blank">' + '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' + '<INPUT value="Get Directions" TYPE="SUBMIT">' + '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + // "(" + name + ")" + '"/>'; // The info window version with the "to here" form open from_htmls[i] = html + '<br>Directions: <a href="javascript:tohere(' + i + ')">To here</a> - <b>From here</b>' + '<br>End address:<form action="http://maps.google.com/maps" method="get"" target="_blank">' + '<input type="text" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>' + '<INPUT value="Get Directions" TYPE="SUBMIT">' + '<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() + // "(" + name + ")" + '"/>'; // The inactive version of the direction info html = html + '<br>Directions: <a href="javascript:tohere('+i+')">To here</a> - <a href="javascript:fromhere('+i+')">From here</a>'; GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); }); // save the info we need to use later for the GMapSidebar gmarkers[i] = marker; htmls[i] = html; // add a line to the GMapSidebar html GMapSidebar_html += '<a href="javascript:myclick(' + i + ')">' + name + '</a><br>'; i++; return marker; } // This function picks up the click and opens the corresponding info window function myclick(i) { gmarkers[i].openInfoWindowHtml(htmls[i]); } // functions that open the directions forms function tohere(i) { gmarkers[i].openInfoWindowHtml(to_htmls[i]); } function fromhere(i) { gmarkers[i].openInfoWindowHtml(from_htmls[i]); } // create the map var map = new GMap2(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(35.828186,-86.065161), 14); // Read the data from map.xml var request = GXmlHttp.create(); request.open("GET", "map.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 html = markers[i].getAttribute("html"); var label = markers[i].getAttribute("label"); // create the marker var marker = createMarker(point,label,html); map.addOverlay(marker); } // put the assembled GMapSidebar_html contents into the GMapSidebar div document.getElementById("GMapSidebar").innerHTML = GMapSidebar_html; } } request.send(null); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } // This Javascript is based on code provided by the // Blackpool Community Church Javascript Team // http://www.commchurch.freeserve.co.uk/ // http://www.econym.demon.co.uk/googlemaps/ //]]> </script>[/quote]--XML FILE--[quote]<markers> <marker lat="35.827818" lng="-86.072576" html="<b/>First Baptist Church</b/> <br /> 405 West Main Street, <br /> Woodbury, TN 37190" label="FBC"/></markers>[/quote] Link to comment https://forums.phpfreaks.com/topic/34626-google-map-api-issue-with-address-to-latlong/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.