因为我不与 Google Maps Api 中的商店查找器相处(请参阅我的其他未回答的问题)我试图以另一种方式应对它:通过 php-mysql-query 和 xml-file 将所有位置放入地图和通过文本输入搜索我自己的位置。每项工作单独工作都很好,但是在组合时,我没有得到我所在位置的标记,即地理编码器似乎无法正常工作。但是:当我输入一个废话地址时,我得到一个正确的错误信息。所以在我看来,地理编码的标记无法显示,但我不知道为什么。有人可以帮忙吗?这是示例(http://umwelt-und-information.com/maps/ASPE_Adressen_zeigen.php),代码如下:
<?php
//error_reporting(E_ALL);
require("dbpass.php");
if (PHP_VERSION>='5')
require_once('domxml-php4-to-php5.php');
// Opens a connection to a mySQL server
$connection=mysql_connect ($dbhost, $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());
}
// Start XML file, create parent node
$doc = domxml_new_doc("1.0");
$node = $doc->create_element("markers");
$parnode = $doc->append_child($node);
// Select all the rows in the ASPE table
$query = "SELECT DISTINCT Nachname, lng, lat, Strasse, Telefon_P, Telefon_D, Telefon_M FROM ASPE";
$result = mysql_query($query) or die ("Error in query: $query " . mysql_error());
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $doc->create_element("marker");
$newnode = $parnode->append_child($node);
$newnode->set_attribute("Nachname", $row['Nachname']);
$newnode->set_attribute("Strasse ", $row['Strasse']);
$newnode->set_attribute("Telefon_P", $row['Telefon_P']);
$newnode->set_attribute("Telefon_D", $row['Telefon_D']);
$newnode->set_attribute("Telefon_M", $row['Telefon_M']);
$newnode->set_attribute("lat", $row['lat']);
$newnode->set_attribute("lng", $row['lng']);
}
$xmlfile = $doc->dump_file("ASPE.xml");
mysql_close($connection);
//header("Location: http://umwelt-und-information.com/maps/kartenansicht_Art.php");
?>
<script src="http://maps.google.com/maps/api/js?sensor=false"
type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var map;
var geocoder;
var markers = [];
var infoWindow;
var iconimage = 'ok.png';
// Geocoder
geocoder = new google.maps.Geocoder();
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
// map.setZoom(15);
var iconimage2 = 'correct.png';
var marker = new google.maps.Marker({
map: map,
icon: iconimage2,
position: results[0].geometry.location
});
} else {
alert("Zu Ihren Angaben konnte kein Fundort gefunden werden: " + status);
}
});
}
function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(52.6145, 8.3418),
zoom: 13,
mapTypeId: 'roadmap',
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}
});
infoWindow = new google.maps.InfoWindow();
downloadUrl("ASPE.xml?ienocache="+new Date().getMilliseconds(), function(data){
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < markers.length; i++) {
var Nachname = markers[i].getAttribute("Nachname");
var Strasse = markers[i].getAttribute("Strasse");
var Telefon_P = markers[i].getAttribute("Telefon_P");
var Telefon_D = markers[i].getAttribute("Telefon_D");
var Telefon_M = markers[i].getAttribute("Telefon_M");
var latlng = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + "Nachname: " + "</b>" + Nachname + " <br/>" +
"<b>" + "Strasse: " + "</b>" + Strasse + "<br/>" +
"<b>" + "Telefon (p): " + "</b>" + Telefon_P + "<br/>" +
"<b>" + "Telefon (d):" + "</b>" + Telefon_D + "<br/>" +
"<b>" + "Telefon (m):" + "</b>" + Telefon_M + "<br/>";
var marker = new google.maps.Marker({
map: map,
position: latlng,
icon: iconimage
});
bounds.extend(latlng);
map.fitBounds(bounds);
var listener = google.maps.event.addListener(map, "idle", function() {
if (map.getZoom() > 15) map.setZoom(15);
google.maps.event.removeListener(listener);
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open (map, marker);
});
markers.push(marker);
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
//]]>
</script>
</head>
<body onload="load()">
<div> Geben Sie hier eine Adresse zum leichteren Auffinden des Fundortes ein: <br>
<input id="address" type="textbox" value="" size="80">
<input type="button" value="Fundort finden" onclick="codeAddress()"> <br></br></div>
<div id="map" style="width: 600px; height: 500px"></div>
</body>