0

我正在使用phonegap为android制作一个应用程序。

当我使用浏览器时,一切正常。

但是当我使用模拟器时,设备(姜饼和冰淇淋三明治)没有显示结果,当我单击按钮时没有任何反应。

这是我的代码:

索引.html

<script src="js/jquery.js"></script>
<script src="js/klass.min.js"></script>
<script src="js/jquery.mobile-1.1.0.js"></script>
<script src="cordova-2.1.0.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyBMxwZns469iKK_rZiu7m1Z-xD4Qv8jKf0&sensor=true"></script>
<script src="js/jquery.ui.map.full.min.js"></script>
<script type="text/javascript" src="js/jquery.ui.map.extensions.js"></script> 
<script src="js/code.photoswipe-3.0.4.js"></script>
<script src="js/script.js"></script>

<div id="find_hotel" data-role="page">
<div data-role="header">
    <a href="#" data-role="button" data-rel="back" data-icon="back">Back</a> 
    <h3>HOTEL</h3>
</div>
<div data-role="content" id="cat_hotel">
    <a href="#" data-role="button">All</a>
    <a href="#" data-role="button">Star 1</a>
    <a href="#" data-role="button">Star 2</a>
    <a href="#" data-role="button">Star 3</a>
    <a href="#" data-role="button">Star 4</a>
    <a href="#" data-role="button">Star 5</a>
</div>
</div>

<div id="hasilhotel" data-role="page">
</div>

脚本.js

$('#find_hotel').live('pageshow',function(){
$('#cat_hotel').bind('click',function(e){
    var id_subkategori, id_kategori;
    id_kategori=2;
    switch ($(e.target).children().html()) { 
    case 'All': 
        //alert('all');
        id_sub_kategori='';
        break;  
    case 'Star 1': 
       id_sub_kategori=3;
        break; 
    case 'Star 2': 
       id_sub_kategori=4;
        break;  
    case 'Star 3': 
       id_sub_kategori=5;
        break; 
    case 'Star 4': 
       id_sub_kategori=6;
        break; 
    case 'Star 5': 
       id_sub_kategori=7;
        break;      
    }

    navigator.geolocation.getCurrentPosition(function(position){
                var latitude=position.coords.latitude;
                var longtitude=position.coords.longitude;
                var postdata = {'id_sub_kategori':id_sub_kategori,'id_kategori':id_kategori,'latitude':latitude,'longtitude':longtitude};
                var output = $('#hasilhotel');
                var link = 'http://172.19.200.114/TA/php/find.php';
                $.ajax({
                    type: 'POST',
                    url: link,
                    dataType: 'jsonp',
                    data: postdata,
                    jsonp: 'jsoncallback',
                    timeout: 5000,
                    success: function(data){
                        var str='the layout in html';
                        var count=0;
                        $.each(data, function(i,item){
                            str = str +'<li class="ui-li ui-li-static ui-body-c"><a href="#"><h3 class="ui-li-heading"><input type="hidden" value="'+item["id_place"]+'" id="id_place" >'+item["nama_place"]+'     &emsp; :     ('+item["distance"]+' Km)</h3></a></li>';
                            count++;
                        });
                        if(count==0)
                        {
                            str = str +'<li class="ui-li ui-li-static ui-body-c"><h3 class="ui-li-heading">Tidak ada Tempat Terdekat</h3></li>';
                        }
                        str=str+'</ul></div>';
                        output.html(str);
                        $.mobile.changePage('#hasilhotel');
                    },
                    error: function(){
                        alert('There is a problem 6',null,'Error','Ok');
                    }
                });
            });
    });
});

查找.php

include 'db.php';

$longtitude = $_POST["longtitude"];
$latitude = $_POST["latitude"];
$id_sub_kategori=$_POST["id_sub_kategori"];
$id_kategori=$_POST["id_kategori"];

$hasil = mysql_query ("
    select a.*,( 3959 * acos( cos( radians(".$latitude.") ) * cos( radians( a.latitude ) ) * cos( radians( a.longtitude ) - radians(".$longtitude.") ) + sin( radians(".$latitude.") ) * sin( radians( a.latitude ) ) ) ) as distance
    from place a inner join sub_kategori b on a.id_sub_kategori=b.id_sub_kategori
    where a.id_sub_kategori like '%".$id_sub_kategori."%' and b.id_kategori like '%".$id_kategori."%' and
    ( 3959 * acos( cos( radians(".$latitude.") ) * cos( radians( a.latitude ) ) * cos( radians( a.longtitude ) - radians(".$longtitude.") ) + sin( radians(".$latitude.") ) * sin( radians( a.latitude ) ) ) ) < 10");

$arr=array();

while($row=mysql_fetch_array($hasil))
{
    $arr[]=array("id_place"=>$row['id_place'],"nama_place"=>$row['nama_place'],"alamat"=>$row['alamat'],"no_telp"=>$row['no_telp'],
    "longtitude"=>$row['longtitude'],"latitude"=>$row['latitude'],"deskripsi"=>$row['deskripsi'],"distance"=>number_format($row['distance'], 2, '.', ''));
}

echo $_GET['jsoncallback'] . '(' . json_encode($arr) . ');';

有人知道可能是什么问题吗?

4

0 回答 0