我正在创建一个使用google api在两个位置之间提供路线的应用。我的应用程序也经常在Android模拟器和设备上崩溃。 代码和错误日志如下:
码
var map=require('ti.map');
var window = Ti.UI.createWindow({title:'win'});
Ti.Geolocation.getCurrentPosition(function(e){
// ********FOR DEVICE*********
// var clat=e.coords.latitude;
// var clon=e.coords.longitude;
var Map=map.createView({
region:{
/****For Simulator*****/
latitude:28.5015171,
longitude:77.0857142,
/*****For Device******/
// latitude:clat,
// longitude:clon
},
title:Map,
mapType : map.STANDARD_TYPE,
animate : true,
zoom:-10,
regionFit : true,
userLocation : true
});
var Ann=[map.createAnnotation({
/****For Simulator*****/
latitude:28.5015171,
longitude:77.0857142,
/*****For Device*****/
// latitude:clat,
// longitude:clon
title:"I m Here",
subtitle:'My Current Location',
pincolor:map.ANNOTATION_RED,
}),
map.createAnnotation({
latitude:28.5686,
longitude:77.1122,
title:"Destination",
subtitle:"I wish to be there",
pincolor:map.Annotation_GREEN,
})];
Map.addAnnotations(Ann);
// Method to check Location On Device
// if (e.error) {
// alert('HFL cannot get your current location');
// return;
// } else {
/*********For Device***/
// longitude = clon;
// latitude = clat;
/****For Simulator*****/
latitude=28.5015171,
longitude=77.0857142,
// Assign the destination Latitude and Longitude.
destinationLongitude = 77.1122;destinationLatitude=28.5686;
// The bellow URL is used to Get the route of current location to assigned destination Location.
var url = "http://maps.googleapis.com/maps/api/directions/json?origin=" + latitude+','+longitude + "&destination=" + destinationLatitude +','+ destinationLongitude +"&sensor=true";
// The Bellow URL use the static current location to destination Location.
// var url = "http://maps.googleapis.com/maps/api/directions/json? origin=37.422502,-122.0855498&destination=37.389569,-122.050212&sensor=true";
var xhr = Titanium.Network.createHTTPClient();
xhr.open('GET', url);
Ti.API.info('URL: ' + url);
xhr.onload = function() {
Ti.API.info('inside the xhr-->' + this.responseText);
var xml = this.responseText;
var points = [];
// Bellow Variable have the step of the current location to destination Location. Using the Steps we going to create a route.
var position = JSON.parse(this.responseText).routes[0].legs[0].steps;
if (position[0] != null) {
points.push({
latitude : position[0].start_location.lat,
longitude : position[0].start_location.lng,
});
// Here we use the for loop to collect all the steps and push it to the array and use this array to form the route in android.
for (var i = 0; i < position.length; i++){
points.push({
latitude : position[i].end_location.lat,
longitude : position[i].end_location.lng,
});
}
}
var route=map.addRoute({
points:points,
width:4,
color:'blue'
});
Map.add(route);
};
// };
window.open();
window.add(Map);
});
错误日志
[INFO] : TiRootActivity: (main) [0,0] checkpoint, on root activity resume. activity = com.and.AndroidmapActivity@417def20
[WARN] : InputMethodManager: startInputInner : InputBindResult == null
[WARN] : dalvikvm: VFY: unable to resolve static field 3896 (MapAttrs) in Lcom/google/android/gms/R$styleable;
[WARN] : dalvikvm: VFY: unable to resolve static field 3886 (common_google_play_services_unknown_issue) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3886 (common_google_play_services_unknown_issue) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3881 (common_google_play_services_install_title) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3877 (common_google_play_services_enable_title) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3892 (common_google_play_services_update_title) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3889 (common_google_play_services_unsupported_title) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3885 (common_google_play_services_network_error_title) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3886 (common_google_play_services_unknown_issue) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3886 (common_google_play_services_unknown_issue) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3883 (common_google_play_services_invalid_account_title) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3886 (common_google_play_services_unknown_issue) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3889 (common_google_play_services_unsupported_title) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3878 (common_google_play_services_install_button) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3875 (common_google_play_services_enable_button) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3890 (common_google_play_services_update_button) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3886 (common_google_play_services_unknown_issue) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3880 (common_google_play_services_install_text_tablet) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3879 (common_google_play_services_install_text_phone) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3876 (common_google_play_services_enable_text) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3891 (common_google_play_services_update_text) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3888 (common_google_play_services_unsupported_text) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3884 (common_google_play_services_network_error_text) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3882 (common_google_play_services_invalid_account_text) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3887 (common_google_play_services_unsupported_date_text) in Lcom/google/android/gms/R$string;
[WARN] : dalvikvm: VFY: unable to resolve static field 3886 (common_google_play_services_unknown_issue) in Lcom/google/android/gms/R$string;
[ERROR] : GooglePlayServicesUtil: The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
[INFO] : I/Google Maps Android API: Google Play services client version: 4132500
[INFO] : dalvikvm: Could not find method gui.a, referenced from method gqh.a
[WARN] : dalvikvm: VFY: unable to resolve static method 24934: Lgui;.a (Landroid/content/Context;)Lgrh;
[ERROR] : dalvikvm: Could not find class 'gpq', referenced from method gpr.a
[WARN] : dalvikvm: VFY: unable to resolve new-instance 4090 (Lgpq;) in Lgpr;
[ERROR] : dalvikvm: Could not find class 'gpq', referenced from method gpr.a
[WARN] : dalvikvm: VFY: unable to resolve new-instance 4090 (Lgpq;) in Lgpr;
[ERROR] : dalvikvm: Could not find class 'gpq', referenced from method gpr.a
[WARN] : dalvikvm: VFY: unable to resolve new-instance 4090 (Lgpq;) in Lgpr;
[INFO] : I/Google Maps Android API: Google Play services package version: 5089034
[WARN] : dalvikvm: VFY: unable to resolve static field 20875 (t) in Lyo;
[WARN] : dalvikvm: VFY: unable to resolve static field 20875 (t) in Lyo;
[INFO] : dalvikvm: Failed resolving Lcom/google/android/gms/location/internal/ParcelableGeofence; interface 4023 'Lglm;'
[WARN] : dalvikvm: Link of class 'Lcom/google/android/gms/location/internal/ParcelableGeofence;' failed
[ERROR] : dalvikvm: Could not find class 'com.google.android.gms.location.internal.ParcelableGeofence', referenced from method gls.a
[WARN] : dalvikvm: VFY: unable to resolve check-cast 2086 (Lcom/google/android/gms/location/internal/ParcelableGeofence;) in Lgls;
[WARN] : dalvikvm: VFY: unable to resolve static field 3896 (MapAttrs) in Lcom/google/android/gms/R$styleable;
[WARN] : dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40dd8258)
[ERROR] : TiApplication: (main) [2486,2486] Sending event: exception on thread: main msg:java.lang.ClassCastException: ti.map.AnnotationProxy cannot be cast to java.lang.Object[]; Titanium 3.3.0,2014/07/11 12:36,787cd39
[ERROR] : TiApplication: java.lang.ClassCastException: ti.map.AnnotationProxy cannot be cast to java.lang.Object[]
[ERROR] : TiApplication: at ti.map.TiUIMapView.processMapProperties(TiUIMapView.java:156)
[ERROR] : TiApplication: at ti.map.TiUIMapView.onViewCreated(TiUIMapView.java:111)
[ERROR] : TiApplication: at org.appcelerator.titanium.view.TiUIFragment.handleMessage(TiUIFragment.java:65)
[ERROR] : TiApplication: at android.os.Handler.dispatchMessage(Handler.java:95)
[ERROR] : TiApplication: at android.os.Looper.loop(Looper.java:154)
[ERROR] : TiApplication: at android.app.ActivityThread.main(ActivityThread.java:4624)
[ERROR] : TiApplication: at java.lang.reflect.Method.invokeNative(Native Method)
[ERROR] : TiApplication: at java.lang.reflect.Method.invoke(Method.java:511)
[ERROR] : TiApplication: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
[ERROR] : TiApplication: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
[ERROR] : TiApplication: at dalvik.system.NativeStart.main(Native Method)
[WARN] : TiVerify: (Timer-0) [2385,4871] Verifying module licenses...
[INFO] : Process: Sending signal. PID: 31701 SIG: 9
任何帮助都会被贬低。