finalHandlermHandler=newHandler();
finalRunnablemUpdateResults=newRunnable(){
publicvoidrun(){
updateUI();
}
};

//Progressdialogtoshowwhenrouteisbeingcalculated
ProgressDialogdialog;
//Spatialreferencesusedforprojectingpoints
finalSpatialReferencewm=SpatialReference.create(3857);
finalSpatialReferenceegs=SpatialReference.create(4326);
//Indexofthecurrentlyselectedroutesegment(-1=noselection)
intselectedSegmentID=-1;

/**Calledwhentheactivityisfirstcreated.*/
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

//RetrievethemapandinitialextentfromXMLlayout
map=(MapView)findViewById(R.id.map);
//AddtiledlayertoMapView

tileLayer=newArcGISTiledMapServiceLayer("http://192.168.183.232:8399/arcgis/rest/services/test1/MapServer");
map.addLayer(tileLayer);

//Addtheroutegraphiclayer(showsthefullroute)
routeLayer=newGraphicsLayer();
map.addLayer(routeLayer);

//InitializetheRouteTask
try{
mRouteTask=RouteTask.createOnlineRouteTask("http://192.168.183.232:8399/arcgis/rest/services/map/NAServer/route1",null);
}catch(Exceptione1){

e1.printStackTrace();
}

//Addthehiddensegmentslayer(forhighlightingroutesegments)
hiddenSegmentsLayer=newGraphicsLayer();
map.addLayer(hiddenSegmentsLayer);

//MakethesegmentHidersymbol"invisible"
segmentHider.setAlpha(1);

//Getthelocationserviceandstartreadinglocation.Don'tauto-pan
//tocenterourposition
LocationServicels=map.getLocationService();
ls.setLocationListener(newMyLocationListener());
ls.start();
ls.setAutoPan(false);

//SetthedirectionsLabelwithinitialinstructions.
directionsLabel=(TextView)findViewById(R.id.directionsLabel);
directionsLabel.setText(getString(R.string.route_label));

map.setOnSingleTapListener(newOnSingleTapListener(){
privatestaticfinallongserialVersionUID=1L;

publicvoidonSingleTap(floatx,floaty){
//Getallthegraphicswithin20pixelstheclick
int[]indexes=hiddenSegmentsLayer.getGraphicIDs(x,y,20);
//Hidethecurrentlyselectedsegment
hiddenSegmentsLayer.updateGraphic(selectedSegmentID,segmentHider);

if(indexes.length<1){
//Ifnosegmentswerefoundbutthereiscurrentlyaroute,
//zoomtotheextentofthefullroute
if(curRoute!=null){
map.setExtent(curRoute.getEnvelope(),100);
directionsLabel.setText(routeSummary);
}
return;
}
//Otherwiseupdateourcurrentlyselectedsegment
selectedSegmentID=indexes[0];
Graphicselected=hiddenSegmentsLayer.getGraphic(selectedSegmentID);
//Highlightitonthemap
hiddenSegmentsLayer.updateGraphic(selectedSegmentID,segmentShower);
Stringdirection=((String)selected.getAttributeValue("text"));
doubletime=((Double)selected.getAttributeValue("time"))
.doubleValue();
doublelength=((Double)selected.getAttributeValue("length"))
.doubleValue();
//Updatethelabelwiththisdirection'sinformation
Stringlabel=String.format("%s%nTime:%.1fminutes,Length:%.1fmiles",direction,time,length);
directionsLabel.setText(label);
//Zoomtotheextentofthatsegment
map.setExtent(selected.getGeometry(),10);
}

});

map.setOnLongPressListener(newOnLongPressListener(){

privatestaticfinallongserialVersionUID=1L;

publicbooleanonLongPress(finalfloatx,finalfloaty){

//Clearthegraphicsandemptythedirectionslist
routeLayer.removeAll();
hiddenSegmentsLayer.removeAll();
curDirections=newArrayList<String>();
mResults=null;

//retrievetheuserclickedlocation
finalPointloc=map.toMapPoint(x,y);

//Showthattherouteiscalculating
dialog=ProgressDialog.show(RoutingSample.this,"","Calculatingroute...",true);
//SpawntherequestoffinanewthreadtokeepUIresponsive

Threadt=newThread(){
@Override
publicvoidrun(){
try{
Pointlo=newPoint(13396558.7981066,3544132.501);
Pointlol=newPoint(13396551.649,3543855.669);
//Startbuildinguproutingparameters
RouteParametersrp=mRouteTask.retrieveDefaultRouteTaskParameters();
NAFeaturesAsFeaturerfaf=newNAFeaturesAsFeature();
//ConvertpointtoEGS(decimaldegrees)
//Pointp=(Point)GeometryEngine.project(loc,wm,egs); //3857->4326

//Pointp=(Point)GeometryEngine.project(loc,wm,wm); //4326->3857

//Createthestoppoints(startatourlocation,gotopressedlocation)
//Pointp1=(Point)GeometryEngine.project(lo,wm,wm);
//Pointp1=(Point)GeometryEngine.project(mLocation,egs,wm); //4326->3857

//StopGraphicpoint1=newStopGraphic(p1); //3857 13396558.7981066,3544132.501
StopGraphicpoint1=newStopGraphic(lo);
StopGraphicpoint2=newStopGraphic(lol);
rfaf.setFeatures(newGraphic[]{point1,point2});

rfaf.setCompressedRequest(true);
rp.setStops(rfaf); //routeParams.setStops(naFeatures);
//SettheroutingserviceoutputSRtoourmapservice's
rp.setOutSpatialReference(wm);
//SolvetherouteandusetheresultstoupdateUIwhenreceived
//mResults=mRouteTask.solve(rp);//xxxxxxxxxxxx
mResults=mRouteTask.solve(rp);


mHandler.post(mUpdateResults);

//mHandler.postAtFrontOfQueue(mUpdateResults);
//parserJson(mResults);

}catch(Exceptione){

mException=e;
mHandler.post(mUpdateResults);
}
}
};
//Starttheoperation
t.start();
returntrue;
}
});
}

/**
*UpdatestheUIafterasuccessfulrestresponsehasbeenreceived.
*/
voidupdateUI(){
dialog.dismiss();
if(mResults==null){

Toast.makeText(RoutingSample.this,mException.toString(),Toast.LENGTH_LONG).show();
return;
}
curRoute=mResults.getRoutes().get(0);
//Symbolsfortherouteandthedestination(blueline,checkerflag)

SimpleLineSymbolrouteSymbol=newSimpleLineSymbol(Color.BLUE,3);
PictureMarkerSymboldestinationSymbol=newPictureMarkerSymbol(
map.getContext(),getResources().getDrawable(R.drawable.flag_finish));

for(RouteDirectionrd:curRoute.getRoutingDirections()){
HashMap<String,Object>attribs=newHashMap<String,Object>();
attribs.put("text",rd.getText());
attribs.put("time",Double.valueOf(rd.getMinutes()));
attribs.put("length",Double.valueOf(rd.getLength()));
curDirections.add(String.format("%s%nTime:%.1fminutes,Length:%.1fmiles",rd.getText(),rd.getMinutes(),rd.getLength()));
GraphicrouteGraphic=newGraphic(rd.getGeometry(),segmentHider,attribs);
hiddenSegmentsLayer.addGraphic(routeGraphic);
}
//Resettheselectedsegment
selectedSegmentID=-1;

//AddthefullroutegraphicanddestinationgraphictotherouteLayer
GraphicrouteGraphic=newGraphic(curRoute.getRouteGraphic().getGeometry(),routeSymbol);

GraphicendGraphic=newGraphic(
((Polyline)routeGraphic.getGeometry()).getPoint(((Polyline)routeGraphic
.getGeometry()).getPointCount()-1),destinationSymbol);
routeLayer.addGraphics(newGraphic[]{routeGraphic,endGraphic});

//Getthefullroutesummaryandsetitasourcurrentlabel
routeSummary=String.format("%s%nTotaltime:%.1fminutes,length:%.1fmiles",curRoute.getRouteName(),curRoute.getTotalMinutes(),curRoute.getTotalMiles());

directionsLabel.setText(routeSummary);
//Zoomtotheextentoftheentireroutewithapadding
map.setExtent(curRoute.getEnvelope(),250);
}

@Override
protectedvoidonActivityResult(intrequestCode,intresultCode,Intentdata){
super.onActivityResult(requestCode,resultCode,data);
//Responsefromdirectionslistview
if(requestCode==1){
if(resultCode==RESULT_OK){
Stringdirection=data.getStringExtra("returnedDirection");
if(direction==null)
return;
//Lookforthegraphicthatcorrespondstothisdirection
for(intindex:hiddenSegmentsLayer.getGraphicIDs()){
Graphicg=hiddenSegmentsLayer.getGraphic(index);
if(direction.contains((String)g.getAttributeValue("text"))){
//Whenfound,hidethecurrentlyselected,showthenewselection
hiddenSegmentsLayer.updateGraphic(selectedSegmentID,segmentHider);
hiddenSegmentsLayer.updateGraphic(index,segmentShower);
selectedSegmentID=index;
//Updatelabelwithinformationforthatdirection
directionsLabel.setText(direction);
//Zoomtotheextentofthatsegment
map.setExtent(
hiddenSegmentsLayer.getGraphic(
selectedSegmentID).getGeometry(),50);
break;
}
}
}
}
}

privateclassMyLocationListenerimplementsLocationListener{

publicMyLocationListener(){
super();
}

/**
*Iflocationchanges,updateourcurrentlocation.Ifbeingfoundfor
*thefirsttime,zoomtoourcurrentpositionwitharesolutionof20
*/
publicvoidonLocationChanged(Locationloc){
if(loc==null)
return;
booleanzoomToMe=(mLocation==null)?true:false;
mLocation=newPoint(loc.getLongitude(),loc.getLatitude());//4326

if(zoomToMe){

Pointp=(Point)GeometryEngine.project(mLocation,egs,wm);//4326->3857
map.zoomToResolution(p,20.0);
}
}



}



错误的地方用xxxxxxxxxxxxxxxxxxxx标出了
提示错误信息是:org.codehaus.jackson.JsonParseException:Currenttoken(VALUE_STRING)notnumbericcannotusenumbericvalueaccessors

2 个解决方案

#1


提示信息已经很明确了啊,解析json的变量是string,不是数字字符,调试进去看看就知道了

更多相关文章

  1. Android 字符串资源
  2. 在string.xml中调用变量[重复]
  3. 算法 - 给出一个字符串str,输出包含两个字符串str的最短字符串,如
  4. 增强的for循环中局部变量的范围
  5. Java字符与整形的转换问题
  6. java中 16进制字符串 与普通字符串 与 byte数组 之间的转化
  7. Jsp以get方式提交中文及特殊字符,javascript处理乱码问题
  8. 忽略转义字符时拆分字符串
  9. JAVA-全局变量与局部变量-继承-封装-(是三节哦!今天的有点多)

随机推荐

  1. mysql 数据库中表不同 但是列名相同,怎么
  2. SQL从结果数据库中选择subCode及其得分,并
  3. 什么时候最推荐使用mysql_real_escape_st
  4. Atitit 数据库 标准库 &#160;sdk 函数库
  5. mysql如何导出HTML?
  6. wampserver无法启动之mysql疑难杂症
  7. Linux下mysql数据库root无法登录的情况
  8. CentOS 6.5下源码安装mysql 5.5
  9. 在MySQL中将数据从LATIN1转换为UTF8
  10. mysql升级的一些踩坑点