私の Api では、経度と緯度がデータベースから取得されるマップ内のいくつかの場所を表示する必要があります。私は php で作業しています。
1456 次
2 に答える
4
Googleの チュートリアルは優れています。しかし、非推奨の mysql_ 拡張機能を使用しているため、PDOを使用するように変更しました。地図はこちら
<?php
require("phpsqlajax_dbinfo.php");
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
// Opens a connection to a MySQL server
$dbh = new PDO("mysql:host=$host;dbname=$database", $username, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
$stmt = $dbh->query('SELECT * FROM markers WHERE 1');
// setting the fetch mode
$stmt->setFetchMode(PDO::FETCH_ASSOC);
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while($row = $stmt->fetch()) {
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("name", $row['name']);
$newnode->setAttribute("address", $row['address']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("type", $row['type']);
}
echo $dom->saveXML();
}
catch(PDOException $e) {
echo "Error .". $e->getMessage() ;// Remove or modify after testing
file_put_contents('PDOErrors.txt',date('[Y-m-d H:i:s]').", phpsqlajax_genxml.php , ". $e->getMessage()."\r\n", FILE_APPEND);
}
//Close the connection
$dbh = null;
?>
ここで生成された XML を表示できます
phpsqlajax_dbinfo.php
<?
$username="username";
$password="password";
$database="username-databaseName";
?>
于 2012-12-09T14:48:11.373 に答える
2
これがリファレンスです。それはあなたを助けるかもしれませんhttps://developers.google.com/maps/articles/phpsqlajax_v3
于 2012-12-09T12:53:34.483 に答える