Sigo los pasos marcados en google (combina php, javascript, xml y googlemap): https://developers.google.com/maps/documentation/javascript/mysql-to-maps?hl=es pero lo que sucede es que una vez creada la web, la base dedatos, es necesario exportarlo a XML pero hay un REQUIRE (phpsqlajax_dbinfo.php) al principio de un fichero que ni se menciona y no creo que sea
El código queda así con el php de conexión yadentro para general el XML que aparece más adelantedespués Googlemap deberá interpretarlo. Pero me da el error:
Error de lectura XML: contenido incorrecto tras un elemento XML del documento
Ubicación: http://localhost/googlemap/google-maps.php
Número de línea 22, columna 1:<markers><marker name="Hunter Gatherer" address="Greenwood Plaza, 36 Blue St, North Sydney NSW" lat="-33.840282" lng="151.207474" type="bar" /><marker name="The Potting Shed" address="7A, 2 Huntley Street, Alexandria, NSW" lat="-33.910751" lng="151.194168" type="bar" /><marker name="Nomad" address="16 Foster Street, Surry Hills, NSW" lat="-33.879917" lng="151.210449" type="bar" /><marker name="Three Blue Ducks" address="43 Macpherson Street, Bronte, NSW" lat="-33.906357" lng="151.263763" type="restaurant" /><marker name="Single Origin Roasters" address="60-64 Reservoir Street, Surry Hills, NSW" lat="-33.881123" lng="151.209656" type="restaurant" /><marker name="Red Lantern" address="60 Riley Street, Darlinghurst, NSW" lat="-33.874737" lng="151.215530" type="restaurant" /></markers>
^
<?php!DOCTYPE html >
require("phpsqlajax_dbinfo <head>
<meta name="viewport" content="initial-scale=1.php");0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Using MySQL and PHP with Google Maps</title>
<style>
/* StartAlways XMLset filethe map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, createbody parent{
node height: 100%;
$doc = domxml_new_doc margin: 0;
padding: 0;
}
</style>
</head>
<?php
require("1"phpsqlajax_dbinfo.0"php");
$node =
function $doc->create_elementparseToXML("markers"$htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$parnode = $doc->append_child$xmlStr=str_replace($node'>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
// Opens a connection to a MySQL server
$connection=mysql_connect ('localhost', $username, $password);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM markers WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '<markers>';
// Iterate through the rows, addingprinting XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// Add to XML document node
$nodeecho '<marker ';
echo 'name="' . parseToXML($row['name']) . '" ';
echo 'address="' . parseToXML($row['address']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'type="' . $row['type'] . '" ';
echo '/>';
}
// End XML file
echo '</markers>';
?>
<body>
<div id="map"></div>
<script>
var customLabel = $doc{
restaurant: {
label: 'R'
},
bar: {
label: 'B'
}
};
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(43.310, ->create_element1.974),
zoom: 14
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP or XML file
downloadUrl("marker"'https://storage.googleapis.com/mapsdevsite/json/mapmarkers2.xml', function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName('marker');
$newnode Array.prototype.forEach.call(markers, function(markerElem) {
var name = $parnode->append_childmarkerElem.getAttribute($node'name');
var address = markerElem.getAttribute('address');
$newnode->set_attribute var type = markerElem.getAttribute("name"'type');
var point = new google.maps.LatLng(
parseFloat(markerElem.getAttribute('lat')),
$row['name'] parseFloat(markerElem.getAttribute('lng')));
$newnode->set_attribute var infowincontent = document.createElement("address",'div');
$row['address'] var strong = document.createElement('strong');
$newnode->set_attribute strong.textContent = name
infowincontent.appendChild("lat"strong);
infowincontent.appendChild(document.createElement('br'));
var text = document.createElement('text');
text.textContent = address
infowincontent.appendChild(text);
var icon = customLabel[type] || {};
var marker = new google.maps.Marker({
map: map,
$row['lat'] position: point,
label: icon.label
});
$newnode->set_attribute marker.addListener("lng"'click', $row['lng']function() {
infoWindow.setContent(infowincontent);
$newnode->set_attribute infoWindow.open("type"map, $row['type']marker);
});
});
});
$xmlfile }
function downloadUrl(url, callback) {
var request = $doc->dump_memwindow.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
echo $xmlfile; }
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?>key=AIzaSyAHEMCKMKBYqimXwIKJX6AK6Sgm1N-fDJw&callback=initMap">
</script>
</body>
</html>
Luego ya vendría comprobrar que funciona el XML, según el documento.
¿Alguien a conseguido el proceso completo?
Un saludo y gracias.