【发布时间】:2012-12-14 04:39:54
【问题描述】:
是否有从 mysql 获取 Google Maps 坐标的正确方法?
我目前的做法是使用 jQuery 脚本从填充元素中获取坐标,我使用 MySQL 填充坐标列表。
// jQuery script to get the coordinates
var coordArray = [];
$(".marker").each(function(index,div)
{
var coords = $(this).data("coords").split(",");
coordArray.push([coords[0],coords[1]]);
});
//while loop in PHP and I have displayed the coordinates within a <div> element:
while($row = $sql->fetch(PDO::FETCH_ASSOC))
{
<div class="marker" data-coords="<?php echo $row['lat'].",".$row['lng'];?>">stuff</div>
}
有没有更好的方法?或者这样也可以吗?
【问题讨论】:
-
使用 JSON.. 效率更高
-
@charlietfl 你介意举个例子我会怎么做吗?或者如果有一个如何做到这一点的例子?
标签: jquery mysql optimization google-maps-api-3