Perhaps this would have been better placed in the Javascript, but I felt it'd get a better response here.
I have an XML file with the following values in:
'postcode' (zip code in UK) stored in a db
'username' - username stored in a db
All I'm trying to do is display the contents of the XML file via Google Maps, so that a marker appears on every postcode. I'm getting a weird error that causes the Google Maps marker to appear 5 miles out to sea... Anyone know why this could be? Here is my code.
Code:
<script type="text/javascript">
//<![CDATA[
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);
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(50, -0.0), 8);
GDownloadUrl("genxml.php", function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("postcode");
var marker = createMarker(name);
map.addOverlay(marker);
}
});
}
}
function createMarker(name) {
var marker = new GMarker;
var html = "<b>" + name + "</b> <br/>";
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
//]]>
</script>
The XML file is fine, and is called genxml.php above.
Last edited by spunko2010; 10-26-2008 at 08:51 PM..
|