View Full Version : Javascript and PHP and Google maps

08-21-2007, 04:32 PM

I'm trying to dynamically generate markers on a google map. I have a php object that holds the coordinates for a few locations.

This is my javascript function that is called when the page is loaded

function load() {
if (GBrowserIsCompatible()) {
//Create the map object
var map = new GMap2(document.getElementById("mashup"));
//add the zoom and pan control
map.addControl(new GLargeMapControl());
//center the map
map.setCenter(new GLatLng(51.535, -0.1214), 12);

//Create the basic icon
var baseIcon = new GIcon();
baseIcon.shadow = "/support/img/myspoonfed/googleShadow.png";
baseIcon.image = "/support/img/myspoonfed/googleType2.png";
baseIcon.iconSize = new GSize(20, 44);
baseIcon.shadowSize = new GSize(55, 40);
baseIcon.iconAnchor = new GPoint(9, 44);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);
baseIcon.infoShadowAnchor = new GPoint(18, 25);

//loop through the list of events and generate markers
<?php foreach ($obj->all as $key => $value) {?>
var point = new GLatLng(<?= $value["location_latitude"]?>,<?= $value["location_longitude"]?>);
var marker = new GMarker(point, baseIcon);

GEvent.addListener (marker, "click", function () {


<?php } ?>


Why doesn't this work?

Many thanks.

08-21-2007, 08:30 PM
can you be more specific than 'it doesnt work?'

Have you checked that your co-ordinates are the right way around?