douwen1901 2013-05-08 14:32
浏览 19
已采纳

使用php和mysql与jquery bMap

For a university project I am creating a website that helps you find golf courses around Ireland & N.Ireland. I have done this using bMap - jquery and google maps. You can choose a county from a sidebar and be shown it on the map. I have used the following code to do this:

$(document).ready(function(){ 
    $("#map").bMap({
        mapZoom: 8,
        mapCenter:[53.65115,    -8.81104],
        mapSidebar:"sideBar", //id of the div to use as the sidebar
        markers:{"data":[
                {"lat":"54.66625","lng":"-6.28647","title":"County Antrim","rnd":"1","body":"There are 38 golf clubs in County Antrim, <a href='counties/antrim.html'>View here</a>"},

                {"lat":"54.29401","lng":"-6.66592","title":"County Armagh","rnd":"1","body":"There are 8 golf clubs in County Armagh, <a href='counties/armagh.html'>View here</a>"},

What I am wondering is there a way I can create a database and use php/mysql to show the same results. I need it to be County Antrim, County Armagh, etc.

Thanks in advance for any help.

  • 写回答

1条回答 默认 最新

  • dqcj32855 2013-05-08 14:42
    关注

    Store the courses in the database with the columns required such as latitude, longitude, title, rnd, body. Then build a string with them, and reference that in the JavaScript code.

    $course_data = "";
    $sql = "SELECT * FROM golf_courses";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result)) {
        $course_data .= '{"lat":"' . $row['latitude'] . '","lng":"' . $row['longitude'] . '","title":"' . $row['title'] . '","rnd":"' . $row['rnd'] . '","body":"' . $row['body'] . '"},'
    }
    

    And then in your code, reference the course_data variable, for example:

    $(document).ready(function(){ 
        $("#map").bMap({
            mapZoom: 8,
            mapCenter:[53.65115,    -8.81104],
            mapSidebar:"sideBar", //id of the div to use as the sidebar
            markers:{"data":[
                    <?php echo $course_data; ?>
    

    Remember this is an example and will need some playing around with to get the database tables right etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用yolov5-7.0目标检测报错
  • ¥15 对于这个问题的解释说明
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备