私は Google Maps Api のストア ファインダーとうまくいかないので (私の他の未回答の不満を参照)、別の方法で対処しようとしました: php-mysql-query と xml-file を介してすべての場所をマップに入れ、テキスト入力で自分の場所を検索します。それぞれのジョブは個別にうまく動作しますが、結合すると自分の位置のマーカーが得られません。つまり、ジオココーダーが正しく動作していないようです。BUT:ナンセンスアドレスを入力すると、正しいエラーメッセージが表示されます。そのため、ジオコーディングのマーカーが表示されないように思えますが、理由はわかりません。誰か助けてくれませんか?これが例 (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>