我有一个包含正方形坐标记录的数据库。
使用谷歌地图API我想使用数据库中的记录来绘制多边形。
我有一些 PHP 经验,并且认为我可以使用 PHP 将数据库数据传递给 JavaScript。
我认为这可以通过 XML 来完成,如果是这样,我会编写 PHP 来访问数据库并将数据加载到内存中
PHP
require_once 'login.php';
$connection = new mysqli($db_hostname, $db_username, $db_password, $db_database);
if ($connection->connect_error) die ($connection->connect_error);
$query = "SELECT * FROM BC_BBA_SquaresCoordinates";
$result = $connection->query($query);
if (!$result) die ($connection->error);
$rows = $result->num_rows;
for($j=0;$j<$rows;++$j){
$result->data_seek($j);
$row = $result->fetch_array(MYSQLI_ASSOC);
}
$result->close();
$connection->close();
JS
downloadUrl("test1.php", function(data){
var xml = data.responseXML;
var row = xml.documentElement.getElementsByTagName("row");
for (var i = 0; i < row.length; i++){
var squarenum = row[i].getAttribute("SQUARE_ID");
}
});
我对 XML 不太熟悉,所以可能我没有正确编码 PHP。任何有关此问题的帮助将不胜感激。
最佳答案
谢谢你,
我能够使用
在谷歌地图上绘制约 11000 个多边形var SquareCoords = [
{lat: parseFloat(markers[i].getAttribute("latone")), lng: parseFloat(markers[i].getAttribute("lngone"))},
{lat: parseFloat(markers[i].getAttribute("lattwo")), lng: parseFloat(markers[i].getAttribute("lngtwo"))},
{lat: parseFloat(markers[i].getAttribute("latone")), lng: parseFloat(markers[i].getAttribute("lngone"))},
{lat: parseFloat(markers[i].getAttribute("lattwo")), lng: parseFloat(markers[i].getAttribute("lngtwo"))},
{lat: parseFloat(markers[i].getAttribute("latthird")), lng: parseFloat(markers[i].getAttribute("lng Three"))},
{lat: parseFloat(markers[i].getAttribute("latthird")), lng: parseFloat(markers[i].getAttribute("lng Three"))},
{lat: parseFloat(markers[i].getAttribute("latfour")), lng: parseFloat(markers[i].getAttribute("lngfour"))},
{lat: parseFloat(markers[i].getAttribute("latfour")), lng: parseFloat(markers[i].getAttribute("lngfour"))},
];
// Construct the polygon.
var drawSquare = new google.maps.Polygon({
paths: squareCoords,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 3,
fillColor: '#FF0000',
fillOpacity: 0.35
});
关于php - Mysql + PHP + 谷歌地图 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35593534/