我爲Android創建了一個簡單的應用程序。我有一個錯誤:「腳本錯誤:$ jq('#map')。panTo不是函數」 我嘗試了很多更改,但錯誤依然存在。我錯在哪裏? 在此先感謝。 的代碼是:jquerymobile和傳單方法不起作用
<script>
//Called after application is started.
function OnStart()
{
\t var osmUrl = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
\t osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
\t osm = L.tileLayer(osmUrl, {
\t maxZoom: 18,
\t attribution: osmAttrib
\t });
\t var map = L.map('map').setView([0, 0], 2).addLayer(osm);
\t marker= L.marker(map.getCenter()).addTo(map)//.bindPopup("<b>Actual Position</b>").openPopup();
\t
loc = app.CreateLocator("GPS,Network");
\t loc.SetOnChange(loc_OnChange);
\t loc.SetRate(0.2); //10 seconds.
\t loc.Start();
sns = app.CreateSensor("Accelerometer");
sns.SetOnChange(sns_OnChange);
sns.Start();
}
//Called when we get a change in location.
var $jq = jQuery.noConflict();
function loc_OnChange(data)
{
\t $jq('#field_GPS').text(data.provider);
\t $jq('#field_GPS').append("<br>Lat "+data.latitude+", Lng "+data.longitude
\t \t +", Alt "+data.altitude);
\t $jq('#field_GPS').append("<br>Spd "+data.speed+", Bear "+data.bearing
\t \t +", Accu "+data.accuracy);
\t \t
\t marker.setLatLng([data.latitude, data.longitude ]).update();
\t $jq('#map').panTo(marker.getLatLng, 8, {animation: true});
// \t map.panTo([50, 30]);
\t //$('#map').fitBounds(marker.getBounds());
}
function sns_OnChange(x, y, z, time)
{
$jq('#field_ACC').text("x="+x + "\n y="+y + "\n z="+z);
}
</script>
<html>
<head>
<meta name="viewport" content="width=device-width">
<script src='file:///android_asset/app.js'></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
\t <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
\t
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script type='text/javascript' src='http://code.jquery.com/jquery-1.11.3.js'></script>
<script type='text/javascript' src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
\t //<script type="text/javascript" src="http://gc.kis.scr.kaspersky-labs.com/1B74BD89-2A22-4B93-B451-1C9E1052A0EC/main.js" charset="UTF-8"></script>
//<script src="/vendor/leaflet/addons/leaflet.markercluster.js"></script>
//<script src="/vendor/leaflet/addons/leaflet.hash.js"></script>
//<script src="/vendor/leaflet/addons/leaflet.makimarkers.js"></script>
//<script src="/vendor/leaflet/addons/leaflet.listmarkers.min.js"></script>
//<link rel="stylesheet" href="/vendor/leaflet/addons/css/leaflet.markercluster.css" />
</head>
\t
<style>
\t body { background-color: #ffffff; }
.hello
{
font-size: 42;
width: 100%;
margin-top: 2em;
text-align: center;
color: blue;
}
#map {
\t \t \t width: 100%;
\t \t \t height: 400px;
\t \t }
</style>
<body onload="app.Start()">
\t <div data-role="page">
\t <div data-role="header">
\t \t <h1 style="text-align:center;">Traking Sensor</h1>
\t </div><!-- /header -->
\t <div role="main" class="ui-content">
\t \t <div id="field_GPS">GPS GOES HERE</div>
\t \t <div id="field_ACC" style="color:#0000FF">ACCELEROMETER GOES HERE</div>
\t \t <div id='map'></div>
\t </div><!-- /content -->
\t <div data-role="footer" data-position="fixed">
\t \t <h4 style="text-align:center;">Ing. Marco Salvatori</h4>
\t </div><!-- /footer -->
</div><!-- /page -->
\t
</body>
</html>
jQuery中確實沒有_panTo_的方法:http://api.jquery.com/?s=panto - panTo是Google地圖的一種方法,而不是jQuery –
什麼是類似panTo的傳單方法? – Marco