문제

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> 
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top