我有一个问题,我一直试图解决一段时间。不幸的是,我似乎无法修复它。
我无法在标记上画一条线,我能够做到。
这是我的代码:
function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(52.37, 4.9),
zoom: 7,
mapTypeId: 'roadmap'
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("maps_marker.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("gpx");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("id");
var address = markers[i].getAttribute("id");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + name + "</b> <br/>" + address;;
var marker = new google.maps.Marker({
map: map,
position: point,
icon: {
path: google.maps.SymbolPath.CIRCLE,
scale: 3
},
});
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);
});
}
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() {}
//]]>
它使用我加载到数据库中的点以及我在此文件中调用的点:
$dom = new DOMDocument("1.0");
$node = $dom->createElement("gpx");
$parnode = $dom->appendChild($node);
$connection=mysql_connect ('localhost', $username, $password);
if (!$connection) { die('Not connected : ' . mysql_error());}
// Set the active MySQL database
$db_selected = mysql_select_db($dbname, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM gpx WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("gpx");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("lat", $row['Lat']);
$newnode->setAttribute("lng", $row['Lon']);
$newnode->setAttribute("id", $row['id']);
}
echo $dom->saveXML();
它在html页面的实际地图中显示我的点,但经过多次尝试后,我无法使折线工作,所以我可以通过我的标记画一条线。 有谁知道如何使它工作?我在互联网上找不到任何例子,他们使用数据库中的两个点并制作折线。