Hi,
you've said you've copy-pasted the code from the example, so you can
modify it somehow like this:
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
GDownloadUrl("phpsqlajax_genxml.php", function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName
("marker");
//modified part
var centerCoord= xml.documentElement.getElementsByTagName
("center");
map.setCenter(new GLatLng(parseFloat(centerCoord.getAttribute
("lat")), parseFloat(centerCoord.getAttribute("lng"))), 13);
//end of modified part
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("type");
var point = new GLatLng(parseFloat(markers[i].getAttribute
("lat")),
parseFloat(markers[i].getAttribute
("lng")));
var marker = createMarker(point, name, address, type);
map.addOverlay(marker);
}
});
}
}
and your xml should look like:
<markers>
<center lat="47.608940" lng="-122.340141" />
<marker name="Pan Africa Market" address="1521 1st Ave, Seattle, WA"
lat="47.608940" lng="-122.340141" type="restaurant"/>
<marker name="Buddha Thai & Bar" address="2222 2nd Ave, Seattle, WA"
lat="47.613590" lng="-122.344391" type="bar"/>
<marker name="The Melting Pot" address="14 Mercer St, Seattle, WA"
lat="47.624561" lng="-122.356445" type="restaurant"/>
<marker name="Ipanema Grill" address="1225 1st Ave, Seattle, WA"
lat="47.606365" lng="-122.337654" type="restaurant"/>
<marker name="Sake House" address="2230 1st Ave, Seattle, WA"
lat="47.612823" lng="-122.345673" type="bar"/>
<marker name="Crab Pot" address="1301 Alaskan Way, Seattle, WA"
lat="47.605961" lng="-122.340363" type="restaurant"/>
<marker name="Mama's Mexican Kitchen" address="2234 2nd Ave, Seattle,
WA" lat="47.613976" lng="-122.345467" type="bar"/>
<marker name="Wingdome" address="1416 E Olive Way, Seattle, WA"
lat="47.617214" lng="-122.326584" type="bar"/>
<marker name="Piroshky Piroshky" address="1908 Pike pl, Seattle, WA"
lat="47.610126" lng="-122.342834" type="restaurant"/>
</markers>
I can't assure that it will work for sure, but I think it should.
On 9 Gru, 20:25, chris barcelona <[email protected]>
wrote:
> Hi,
> I've just written (well, copied and pasted) my first database-dirven
> googlemaps code following the example
> here:http://code.google.com/intl/es-ES/apis/maps/articles/phpsqlajax.html
>
> However, in this example the lat long coordinates for the map CENTRE
> are hard-coded.
> Could anyone point me to a tutorial which explains in easy steps how
> to go about setting the map centre coordinates from a mysql database.
> my javascript,xml skills aren't up to the task of working it out
> myself!
> thanks in advance
> chris
--
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en.