dry18813 2013-04-16 13:22
浏览 24
已采纳

将谷歌地图放入工具提示

I have a page that displays data from a database. I'm using jquery, php and mysqli to display the data. When you mouse over a certain link for each record, I want a tooltip to appear with a google map inside it, showing the location of that record based on the lat and lng from that record in the database. I'm using the jquery ui tooltip.

How do you get a googlemap into a tooltip, though, please?

<script type="text/javascript">

$(function() {
    $( document ).tooltip({

    });
  });

$(window).load(function () {
    $.get('process.php', function(data){
            $('.loading').hide();
            $('#chart').html( data );
        });

});

process.php:

<?php
include_once ('./myfile.php'); 
//open database
$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); //open db conn
if (mysqli_connect_errno()) {
            printf("Connect failed: %s", mysqli_connect_error());
            exit();
}       
$infoboxText = "";

//get list of each muni with its lat and lng    
$qGolf="SELECT * FROM golf";
$result_golf = $db->query($qGolf);
$infoboxText= "<table class='infoboxWindow'><tr><th>Course Name</th><th>Location</th><th>Phone</th><th>Holes</th><th>Daily Fee<br/>9 Holes</th><th>Daily Fee<br/>18 Holes</th><th>Weekend Fee<br/>9 Holes</th><th>Weekend Fee<br/>18 Holes</th><th>Cart Fee<br/>9 Holes</th><th>Cart Fee<br/>18 Holes</th><th>Tee Times</th></tr>";
while($golfList = $result_golf->fetch_array(MYSQLI_ASSOC)) { 

        //build the infobox text with a table to hold the data
        $infoboxText.="<tr><td>" .$golfList["Course_Name"] . "</td>";
        //$infoboxText.="<td><div title='This is a tooltip.' class='locate'>Show</div></td>";
        $infoboxText.="<td><a href='#' title='This is a tooltip.' class='locate'>Show</a></td>";
        $infoboxText.="<td>".$golfList["Phone"]."</td>";
        $infoboxText.="<td>".$golfList["Holes"]."</td>";
        $infoboxText.="<td>".$golfList["Daily_Fee_9_Holes"]."</td>";
        $infoboxText.="<td>".$golfList["Daily_Fee_18_Holes"]."</td>";
        $infoboxText.="<td>".$golfList["Weekend_Fee_9_Holes"]."</td>";
        $infoboxText.="<td>".$golfList["Weekend_Fee_18_Holes"]."</td>";
        $infoboxText.="<td>".$golfList["Cart_Fee_9_Holes"]."</td>";
        $infoboxText.="<td>".$golfList["Cart_Fee_18_Holes"]."</td>";
        $infoboxText.="<td>".$golfList["Tee_Times"]."</td></tr>";
        //close the table



}
$infoboxText.="</table>";
echo $infoboxText; //return the circles code here


?>

html:

<div class="loading">LOADING ...</div>
<div id="chart"> </div> 
  • 写回答

1条回答 默认 最新

  • dtt3399 2013-04-16 13:57
    关注

    I've done this in the past using the Google Static Maps API. We have a load of spans that look like this:

    <a href="#" class="showMap">
    <span class="googlemaps" data-image="http://maps.googleapis.com/maps/api/staticmap?zoom=13&amp;size=400x214&amp;markers=color:green|52.503679,13.448807&amp;sensor=false&amp;key=YOURKEY">Show map</span>
    </a>
    

    Then there's some javascript attached to all those spans that takes that data-image attribute and calls the URL defined there, loading that content as a tooltip:

    // Capture the data-image attribute and attach tool tips to them
    $(document).ready(function() {
        $("span.googlemaps[data-image]").tooltip({
            showURL: false,
            track: true,
            bodyHandler: function() {
                return $("<img/>").attr("src", $(this).attr("data-image"));
            },
            extraClass: "imgTooltip"
        });
    });
    

    This is using the jQuery Tooltip plugin. You can see a working example of this here.

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

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line