0

This retrieves the map of the location:

    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/
1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.cookie.js"></script>
<script type="text/javascript">
function success(position)
{
var s = document.querySelector('#status');
if (s.className == 'success')
{
return;
}
s.innerHTML = "Found you!";
s.className = 'Success';
var mapcanvas = document.createElement('div');
mapcanvas.id = 'mapcanvas';
mapcanvas.style.height = '100%';
mapcanvas.style.width = '100%';
document.querySelector('#map').appendChild(mapcanvas);
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeControl: false,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title:"You are here!"
});
$.cookie("MyLat", position.coords.latitude); // Storing latitude value
$.cookie("MyLon", position.coords.longitude); // Storing longitude value
}
function error(msg)
{
var s = document.querySelector('#status');
s.innerHTML = typeof msg == 'string' ? msg : "failed";
s.className = 'Fail';
}
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(success, error);
}
else
{
error('Not supported'); //HTML Support
}

//Jquery Code
$(document).ready(function()
{
$("#check").click(function()
{
var lat = $.cookie("MyLat");
var lon = $.cookie("MyLon");
alert('Latitued: '+lat);
alert('Longitude: '+lon);
var url="http://maps.googleapis.com/maps/api/geocode/json?latlng="+lat+","+lon+"&sensor=false";
alert('Google Map API: '+url);
//Get Json Request Here
});
});
</script>
//HTML Code
<input type='button' id='check' value='Check-out'/>
<div id="status">Loading.............</div>
<div id="map"></div>

I want to get only city and street address using GPS in jQuery and pass that city location to the PHP below, assigning the city address in php variable $city = //from jquery.

And pass in $sql statement.

(i.e "select e.id, e.firstName, e.lastName, e.title, e.picture, count(r.id) reportCount " . 
                "from employee e left join employee r on r.managerId = e.id " .
                "group by e.id order by e.lastName, e.firstName where e.city=$city";)

    <div data-role="content"> 
    <ul data-role="listview" data-filter="true">
        <?php
        include 'config.php';
        $sql = "select e.id, e.firstName, e.lastName, e.title, e.picture, count(r.id) reportCount " . 
                "from employee e left join employee r on r.managerId = e.id " .
                "group by e.id order by e.lastName, e.firstName";
        try {
            $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);  
            $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $stmt = $dbh->query($sql); 
            while ($emp = $stmt->fetch(PDO::FETCH_OBJ)) {  
                echo "<li><a href='employeedetails.php?id=$emp->id'>" .
                    "<img src='pics/$emp->picture'/>" .
                    "<h4>$emp->firstName $emp->lastName</h4>" .
                    "<p>$emp->title</p>" .
                    "<span class='ui-li-count'>$emp->reportCount</span></a></li>";
            }
            $dbh = null;
        } catch(PDOException $e) {
            echo $e->getMessage(); 
        }
        ?> 
    </ul>
  </div>

</div>

Help me in getting this.

4

2 回答 2

1

您需要使用 jquery ajax

正如我建议看这个

于 2013-03-22T12:19:32.830 回答
0

尝试将您的数据封装在 JSON 中,然后他们使用 AJAX 将其传输到您的 PHP 源。在 jquery 和 PHP 中,您有解析器来编码/解码 json 信息。

于 2013-03-22T12:16:43.253 回答