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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度