我是Phonegap的新手,因为它使用网络技术来编写移动应用程序,我更喜欢使用原始java编码的phonegap,只是为了方便用户界面。 在这个地理位置显示了CAUGHT SECURITY EXCEPTIONS,我不知道从哪里出现。 请帮助..
开始跟踪位置
$("#startTracking_start").live('click', function(){
// Start tracking the User
watch_id = navigator.geolocation.watchPosition(
// Success
function(position){
tracking_data.push(position);
},
// Error
function(error){
console.log(error);
},
// Settings
{ frequency: 3000, enableHighAccuracy: true });
// Tidy up the UI
track_id = $("#track_id").val();
$("#track_id").hide();
$("#startTracking_status").html("Tracking workout: <strong>" + track_id + "</strong>");
});
停止跟踪位置
$("#startTracking_stop").live('click', function(){
// Stop tracking the user
navigator.geolocation.clearWatch(watch_id);
// Save the tracking data
window.localStorage.setItem(track_id, JSON.stringify(tracking_data));
// Reset watch_id and tracking_data
var watch_id = null;
var tracking_data = null;
// Tidy up the UI
$("#track_id").val("").show();
$("#startTracking_status").html("Stopped tracking workout: <strong>" + track_id + "</strong>");
});
跟踪信息页
<div data-role="page" id="track_info">
<div data-role="header">
<h1>Viewing Single route</h1>
<div data-role="navbar">
<ul>
<li><a href="#home" data-transition="none" data-icon="home">Home</a></li>
<li><a href="#startTracking" data-transition="none" data-icon="plus">Track route</a></li>
<li><a href="#history" data-transition="none" data-icon="star">History</a></li>
</ul>
</div>
</div>
<div data-role="content">
<p id="track_info_info"></p>
<div id="map_canvas" style="position:absolute;bottom:0;left:0;width:100%;height:300px;"></div>
</div>
</div>
跟踪信息功能 - 当用户查看“跟踪信息”页面时.. !!
$('#track_info').live('pageshow', function(){
// Find the track_id of the workout they are viewing
var key = $(this).attr("track_id");
// Update the Track Info page header to the track_id
$("#track_info div[data-role=header] h1").text(key);
// Get all the GPS data for the specific workout
var data = window.localStorage.getItem(key);
// Turn the stringified GPS data back into a JS object
data = JSON.parse(data);
// Calculate the total distance travelled
total_km = 0;
for(i = 0; i < data.length; i++){
if(i == (data.length - 1)){
break;
}
total_km += gps_distance(data[i].coords.latitude, data[i].coords.longitude, data[i+1].coords.latitude, data[i+1].coords.longitude);
}
total_km_rounded = total_km.toFixed(2);
// Calculate the total time taken for the track
start_time = new Date(data[0].timestamp).getTime();
end_time = new Date(data[data.length-1].timestamp).getTime();
total_time_ms = end_time - start_time;
total_time_s = total_time_ms / 1000;
final_time_m = Math.floor(total_time_s / 60);
final_time_s = total_time_s - (final_time_m * 60);
// Display total distance and time
$("#track_info_info").html('Started at <strong>'+ start_time +'</strong> and travelled <strong>' + total_km_rounded + '</strong> km in <strong>' + final_time_m + 'm</strong> and <strong>' + final_time_s + 's</strong>');
// Set the initial Lat and Long of the Google Map
var myLatLng = new google.maps.LatLng(data[0].coords.latitude, data[0].coords.longitude);
// Google Map options
var myOptions = {
zoom: 15,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// Create the Google Map, set options
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var trackCoords = [];
// Add each GPS entry to an array
for(i=0; i<data.length; i++){
trackCoords.push(new google.maps.LatLng(data[i].coords.latitude, data[i].coords.longitude));
}
// Plot the GPS entries as a line on the Google Map
var trackPath = new google.maps.Polyline({
path: trackCoords,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
// Apply the line to the map
trackPath.setMap(map);
});
Log_Cat
07-29 23:52:56.896: E/chromium(6931): external/chromium/net/disk_cache/stat_hub.cc:190: [0729/235256:ERROR:stat_hub.cc(190)] StatHub::Init - App com.a_man.trackme isn't supported.
07-29 23:52:56.896: E/chromium(6931): external/chromium/net/disk_cache/stat_hub.cc:190: [0729/235256:ERROR:stat_hub.cc(190)] StatHub::Init - App com.a_man.trackme isn't supported.
07-29 23:53:33.032: E/geolocationService(6931): Caught security exception registering for location updates from system. This should only happen in DumpRenderTree.
07-29 23:53:47.015: E/geolocationService(6931): Caught security exception registering for location updates from system. This should only happen in DumpRenderTree.
07-29 23:53:49.828: E/geolocationService(6931): Caught security exception registering for location updates from system. This should only happen in DumpRenderTree.
07-29 23:53:59.758: E/Web Console(6931): Uncaught SyntaxError: Unexpected token u at file:///android_asset/www/index.html#track_info:1
答案 0 :(得分:0)
您似乎忘了为应用添加正确的权限:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
无论您是否使用本机API或HTML5 API访问用户的位置,都需要这些。