java - android studio: get current gps location after drawing a path while moving -
in app i'm trying :
first draw path between 2 final locations
then show gps coordinates
the problem when execute app stops when execute part draws route alone runs normally, same thing gps coordinates.
here code:
public class mainactivity extends appcompatactivity implements onmapreadycallback, directionfinderlistener, locationlistener { private googlemap map; private list<marker> originmarkers = new arraylist<>(); private list<marker> destinationmarkers = new arraylist<>(); private list<polyline> polylinepaths = new arraylist<>(); private progressdialog progressdialog; public static string origin; public static string destination; private locationmanager locationmanager; private double latitude; private double longitude; private latlng latlng; public static long mintime = 1000;//1000=1s public static float mindis = 1;//1m textview tvlat, tvlon, tvtem, tvdis; float zoom = 16; float tilt = 30; float bearing = (float) 112.5; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); supportmapfragment mapfragment = (supportmapfragment) getsupportfragmentmanager() .findfragmentbyid(r.id.map); mapfragment.getmapasync(this); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); tvlat = (textview) findviewbyid(r.id.tvlat); tvlon = (textview) findviewbyid(r.id.tvlon); tvdis = (textview) findviewbyid(r.id.tvdis); tvtem = (textview) findviewbyid(r.id.tvtem); sendrequest(origin,desination); mygps(); } @override public void onmapready(googlemap googlemap) { map = googlemap; map.getuisettings().iscompassenabled(); map.getuisettings().istiltgesturesenabled(); map.getuisettings().isrotategesturesenabled(); map.getuisettings().isscrollgesturesenabled(); map.getuisettings().iszoomcontrolsenabled(); map.getuisettings().setzoomcontrolsenabled(true); if (activitycompat.checkselfpermission(this, manifest.permission.access_fine_location) != packagemanager.permission_granted && activitycompat.checkselfpermission(this, manifest.permission.access_coarse_location) != packagemanager.permission_granted) { return; } map.setmylocationenabled(true); map.setmaptype(googlemap.map_type_hybrid); map.settrafficenabled(true); map.setbuildingsenabled(false); final latlng firstlatlng = new latlng(first.getlatitude(), first.getlongitude()); map.addmarker(new markeroptions().position(firstlatlng).title("start")); cameraposition cameraposition = new cameraposition.builder() .target(latlng).zoom(zoom).tilt(tilt).bearing(bearing).build(); map.animatecamera(cameraupdatefactory.newcameraposition(cameraposition)); } private void sendrequest(string origin, string destination) { try { new directionfinder(this, origin, destination).execute(); } catch (unsupportedencodingexception e) { e.printstacktrace(); } } @override public void ondirectionfinderstart() { progressdialog = progressdialog.show(this, "patientez svp.", "chargement..!", true); if (originmarkers != null) { (marker marker : originmarkers) { marker.remove(); } } if (destinationmarkers != null) { (marker marker : destinationmarkers) { marker.remove(); } } if (polylinepaths != null) { (polyline polyline : polylinepaths) { polyline.remove(); } } } @override public void ondirectionfindersuccess(list<route> routes) { progressdialog.dismiss(); polylinepaths = new arraylist<>(); originmarkers = new arraylist<>(); destinationmarkers = new arraylist<>(); (route route : routes) { map.movecamera(cameraupdatefactory.newlatlngzoom(route.startlocation, 16)); tvtem.settext("durée:" + route.duration.text); tvdis.settext("distance:" + route.distance.text); originmarkers.add(map.addmarker(new markeroptions() .icon(bitmapdescriptorfactory.fromresource(r.drawable.start_blue)) .title(route.startaddress) .position(route.startlocation))); destinationmarkers.add(map.addmarker(new markeroptions() .icon(bitmapdescriptorfactory.fromresource(r.drawable.end_green)) .title(route.endaddress) .position(route.endlocation))); polylineoptions polylineoptions = new polylineoptions(). geodesic(true). color(color.cyan). width(12); (int = 0; < route.points.size(); i++) { polylineoptions.add(route.points.get(i)); } polylinepaths.add(map.addpolyline(polylineoptions)); } } public void mygps() { locationmanager=(locationmanager) getsystemservice(context.location_service); if(activitycompat.checkselfpermission(this,manifest.permission.access_fine_location)!=packagemanager.permission_granted&&activitycompat.checkselfpermission(this,manifest.permission.access_coarse_location)!=packagemanager.permission_granted) { return; } location location = locationmanager.getlastknownlocation(locationmanager.gps_provider); if(location!=null) { latlng = new latlng(location.getlatitude(), location.getlongitude()); onlocationchanged(location); } locationmanager.requestlocationupdates(locationmanager.gps_provider,mintime,mindis,this); } @override public void onlocationchanged(location location) { latlng=new latlng(location.getlatitude(),location.getlongitude()); longitude = location.getlatitude(); latitude = location.getlatitude(); tvlat.settext("latitue:" + new decimalformat("##.###").format(latitude)); tvlon.settext("longitude:" + new decimalformat("##.###").format(longitude)); map.animatecamera(cameraupdatefactory.newlatlngzoom(latlng, zoom), 2000, null); if (activitycompat.checkselfpermission(this, manifest.permission.access_fine_location) != packagemanager.permission_granted && activitycompat.checkselfpermission(this, manifest.permission.access_coarse_location) != packagemanager.permission_granted) { return; } locationmanager.removeupdates(this); } @override public void onproviderdisabled(string provider) { // todo auto-generated method stub } @override public void onproviderenabled(string provider) { // todo auto-generated method stub } @override public void onstatuschanged(string provider, int status, bundle extras) { // todo auto-generated method stub } @override public void onbackpressed() { super.onbackpressed(); } }
this logcat :
line 28385: 05-25 09:41:20.746 2467 2477 am_create_activity: [0,1146082216,60,com.example.mimiryen.project/.mainactivity,android.intent.action.main,null,null,270532608,com.sec.android.app.launcher,0] line 28391: 05-25 09:41:20.766 2467 2991 am_proc_start: [0,27907,10706,com.example.mimiryen.project,activity,com.example.mimiryen.project/.mainactivity] line 28391: 05-25 09:41:20.766 2467 2991 am_proc_start: [0,27907,10706,com.example.mimiryen.project,activity,com.example.mimiryen.project/.mainactivity] line 28393: 05-25 09:41:20.801 2467 2478 am_proc_bound: [0,27907,com.example.mimiryen.project] line 28394: 05-25 09:41:20.811 2467 2478 am_restart_activity: [0,1146082216,60,com.example.mimiryen.project/.mainactivity,0] line 28397: 05-25 09:41:21.606 27907 27907 am_on_resume_called: [0,com.example.mimiryen.project.mainactivity] line 28398: 05-25 09:41:21.851 2467 2592 am_activity_launch_time: [0,1146082216,com.example.mimiryen.project/.mainactivity,1095,1095,1] line 28399: 05-25 09:41:21.941 2467 2467 notification_cancel: [com.example.mimiryen.project,10436,null,0,0,64] line 28401: 05-25 09:41:22.256 2467 2995 am_crash: [27907,0,com.example.mimiryen.project,13155908,java.lang.nullpointerexception,null,null,-1] line 28402: 05-25 09:41:22.256 2467 2995 am_finish_activity: [0,1146082216,60,com.example.mimiryen.project/.mainactivity,0,crashed] line 28403: 05-25 09:41:22.281 2467 2995 am_pause_activity: [0,1146082216,com.example.mimiryen.project/.mainactivity,0] line 28415: 05-25 09:41:23.361 2467 2593 am_destroy_activity: [0,1146082216,60,com.example.mimiryen.project/.mainactivity,0,finish-imm] line 28416: 05-25 09:41:23.716 2467 2993 am_proc_died: [0,27907,com.example.mimiryen.project,9] line 28422: 05-25 09:41:23.726 1952 1952 sf_frame_dur: [com.example.mimiryen.project/com.example.mimiryen.project.mainactivity,6,2,2,2,0,0,0] line 28422: 05-25 09:41:23.726 1952 1952 sf_frame_dur: [com.example.mimiryen.project/com.example.mimiryen.project.mainactivity,6,2,2,2,0,0,0] line 28424: 05-25 09:41:23.971 1952 1952 sf_frame_dur: [application error: com.example.mimiryen.project,8,0,0,1,0,1,0] line 119144: * recent #6: taskrecord{42576098 #60 a=com.example.mimiryen.project u=0 sz=0} line 119146: affinity=com.example.mimiryen.project line 119147: intent={act=android.intent.action.main cat=[android.intent.category.launcher] flg=0x10200000 cmp=com.example.mimiryen.project/.mainactivity} line 119148: realactivity=com.example.mimiryen.project/.mainactivity line 122678: process com.example.mimiryen.project uid 10706: last crashed +17m48s891ms ago line 124751: package com.example.mimiryen.project: line 137127: 10: [2016-05-25 02:58:01.166] [pid:(3131)]executeforchangedrowcount took 0ms - succeeded, sql="delete logs ((((source_package = 'com.example.mimiryen.project'))) , ((type = 4))) , ( (logtype=500 or logtype=800 or logtype=100 or logtype=120 or logtype=510 or logtype=900 or logtype=110 or logtype=1100 or logtype=1000 or (logs.logtype=200 , number not in (select number logs number '%@%')) or logtype=300 or logtype=950))" line 137128: 11: [2016-05-25 02:58:01.166] [pid:(3131)]prepare took 0ms - succeeded, sql="delete logs ((((source_package = 'com.example.mimiryen.project'))) , ((type = 4))) , ( (logtype=500 or logtype=800 or logtype=100 or logtype=120 or logtype=510 or logtype=900 or logtype=110 or logtype=1100 or logtype=1000 or (logs.logtype=200 , number not in (select number logs number '%@%')) or logtype=300 or logtype=950))" line 137130: 13: [2016-05-25 02:58:01.162] [pid:(3131)]executeforcursorwindow took 3ms - succeeded, sql="select vvm_id logs (((source_package = 'com.example.mimiryen.project'))) , ((type = 4)) , (logtype=500 or logtype=800 or logtype=100 or logtype=120 or logtype=510 or logtype=900 or logtype=110 or logtype=1100 or logtype=1000 or (logs.logtype=200 , number not in (select number logs number '%@%')) or logtype=300 or logtype=950) , type = 4" line 137131: 14: [2016-05-25 02:58:01.161] [pid:(3131)]prepare took 0ms - succeeded, sql="select vvm_id logs (((source_package = 'com.example.mimiryen.project'))) , ((type = 4)) , (logtype=500 or logtype=800 or logtype=100 or logtype=120 or logtype=510 or logtype=900 or logtype=110 or logtype=1100 or logtype=1000 or (logs.logtype=200 , number not in (select number logs number '%@%')) or logtype=300 or logtype=950) , type = 4" line 150680: 43959eb8 com.example.mimiryen.project/.mainactivity filter 43cb62b8 line 150948: 43944a28 com.example.mimiryen.project/com.google.android.gms.appinvite.previewactivity filter 43ca9338 line 154609: 43932da8 com.example.mimiryen.project/com.google.android.gms.measurement.appmeasurementreceiver filter 43ca15a8 line 167014: com.example.mimiryen.project/com.google.android.gms.measurement.appmeasurementcontentprovider: line 167015: provider{43887ef8 com.example.mimiryen.project/com.google.android.gms.measurement.appmeasurementcontentprovider} line 167502: [com.example.mimiryen.project.google_measurement_service]: line 167503: provider{43887ef8 com.example.mimiryen.project/com.google.android.gms.measurement.appmeasurementcontentprovider} line 167504: applicationinfo=applicationinfo{442e7dd0 com.example.mimiryen.project} line 169361: [com.example.mimiryen.project] line 179950: package [com.example.mimiryen.project] (44479588): line 179952: pkg=package{444a0e28 com.example.mimiryen.project} line 179953: codepath=/data/app/com.example.mimiryen.project-7.apk line 179954: resourcepath=/data/app/com.example.mimiryen.project-7.apk line 179955: nativelibrarypath=/data/app-lib/com.example.mimiryen.project-7 line 179958: applicationinfo=applicationinfo{442e7dd0 com.example.mimiryen.project} line 179960: datadir=/data/data/com.example.mimiryen.project line 183823: * com.example.mimiryen.project / u0a704: line 184395: * com.example.mimiryen.project / u0a704: line 185291: * com.example.mimiryen.project / u0a704: line 185749: * com.example.mimiryen.project / u0a704: line 186917: * com.example.mimiryen.project / u0a705: line 187812: * com.example.mimiryen.project / u0a706: line 187863: * com.example.mimiryen.project / u0a705: line 188877: * com.example.mimiryen.project / u0a704: line 188878: process com.example.mimiryen.project (unique, 3 entries): line 188886: myid=44cd45d0 mcommonprocess=44cd45d0 mpackage=com.example.mimiryen.project line 188887: * com.example.mimiryen.project / u0a705: line 188888: process com.example.mimiryen.project (unique, 3 entries): line 188895: myid=44ccfb18 mcommonprocess=44ccfb18 mpackage=com.example.mimiryen.project line 188896: * com.example.mimiryen.project / u0a706: line 188897: process com.example.mimiryen.project (unique, 8 entries): line 188913: myid=4499f948 mcommonprocess=4499f948 mpackage=com.example.mimiryen.project line 198135: * com.example.mimiryen.project / u0a706: line 198205: * com.example.mimiryen.project / u0a705: line 198266: * com.example.mimiryen.project / u0a704: line 198995: * com.example.mimiryen.project / u0a706: line 198996: process com.example.mimiryen.project (unique, 2 entries): line 199000: myid=443b1c90 mcommonprocess=443b1c90 mpackage=com.example.mimiryen.project line 202718: * com.example.mimiryen.project / u0a706: line 203063: * com.example.mimiryen.project / u0a706: line 203064: process com.example.mimiryen.project (unique, 2 entries): line 203068: myid=4398fb00 mcommonprocess=4398fb00 mpackage=com.example.mimiryen.project line 207063: * com.example.mimiryen.project / u0a706: line 209198: spellscroll #154 name=com.example.mimiryen.project, targetpackage=com.example.mimiryen.project line 209198: spellscroll #154 name=com.example.mimiryen.project, targetpackage=com.example.mimiryen.project line 209200: spellscrollcomponent=com.example.mimiryen.project/com.example.mimiryen.project.mainactivity line 209200: spellscrollcomponent=com.example.mimiryen.project/com.example.mimiryen.project.mainactivity line 209208: intent: intent { act=android.intent.action.main cat=[android.intent.category.launcher] cmp=com.example.mimiryen.project/.mainactivity } line 209568: com.example.mimiryen.project: 20 times, 821458 ms line 209569: com.example.mimiryen.project.mainactivity: 20 starts, 2000-3000ms=1, 3000-4000ms=2, 4000-5000ms=2, >=5000ms=4 line 209676: com.example.mimiryen.project: 10 times, 7506 ms line 209677: com.example.mimiryen.project.mainactivity: 10 starts line 209769: com.example.mimiryen.project: 26 times, 637650 ms line 209770: com.example.mimiryen.project.mainactivity: 26 starts, 750-1000ms=1, 1000-1500ms=1, 1500-2000ms=2, 2000-3000ms=7, 3000-4000ms=3, >=5000ms=5 line 209867: com.example.mimiryen.project: 51 times, 1781435 ms line 209868: com.example.mimiryen.project.mainactivity: 51 starts, 0-250ms=5, 250-500ms=5, 500-750ms=1, 750-1000ms=7, 1000-1500ms=4, 1500-2000ms=4, 2000-3000ms=3, 3000-4000ms=1 line 209964: com.example.mimiryen.project: 16 times, 584423 ms line 209965: com.example.mimiryen.project.mainactivity: 16 starts, 750-1000ms=1, 1000-1500ms=4, 1500-2000ms=2, 2000-3000ms=3, 3000-4000ms=1, 4000-5000ms=1 line 213532: pkgproc,com.example.mimiryen.project,10704,,0ne:1688232,1nt:108962,1ne:115963 line 213533: pkgpss,com.example.mimiryen.project,10704,,0ne:4:25524:26098:26679:23124:23565:23964,1nt:2:26267:26731:27195:23552:24002:24452 line 213534: pkgproc,com.example.mimiryen.project,10705,,0nt:596,1nt:359029,1ne:12049 line 213535: pkgpss,com.example.mimiryen.project,10705,,1nt:5:18563:19668:20859:16052:17480:18428 line 213536: pkgproc,com.example.mimiryen.project,10706,,0nt:390042,0ne:36604,0mt:162371,1nt:427884,1nl:1079,1na:5407,1ne:229728,1mt:4645 line 213537: pkgpss,com.example.mimiryen.project,10706,,0nt:6:21939:34286:37025:20420:32553:35216,0ne:1:22879:22879:22879:21444:21444:21444,0mt:2:22957:23005:23054:21448:21468:21488,1nt:7:20776:24143:35303:18672:22269:33596,1ne:2:19690:21285:22880:17964:19704:21444 line 214981: proc,com.example.mimiryen.project,10704,0ne:1688232,1nt:108962,1ne:115963 line 214982: pss,com.example.mimiryen.project,10704,0ne:4:25524:26098:26679:23124:23565:23964,1nt:2:26267:26731:27195:23552:24002:24452 line 214983: proc,com.example.mimiryen.project,10705,0nt:596,1nt:359029,1ne:12049 line 214984: pss,com.example.mimiryen.project,10705,1nt:5:18563:19668:20859:16052:17480:18428 line 214985: proc,com.example.mimiryen.project,10706,0nt:390042,0ne:36604,0mt:162371,1nt:427884,1nl:1079,1na:5407,1ne:229728,1mt:4645 line 214986: pss,com.example.mimiryen.project,10706,0nt:6:21939:34286:37025:20420:32553:35216,0ne:1:22879:22879:22879:21444:21444:21444,0mt:2:22957:23005:23054:21448:21468:21488,1nt:7:20776:24143:35303:18672:22269:33596,1ne:2:19690:21285:22880:17964:19704:21444 line 215411: pkgproc,com.example.mimiryen.project,10706,,1nt:2558,1ne:354 line 216034: proc,com.example.mimiryen.project,10706,1nt:2558,1ne:354 line 216275: pkgproc,com.example.mimiryen.project,10706,,1nt:2558,1ne:354 line 216898: proc,com.example.mimiryen.project,10706,1nt:2558,1ne:354 line 217106: p:com.example.mimiryen.project,20,821458 line 217107: a:com.example.mimiryen.project.mainactivity,20,0,0,0,0,0,0,1,2,2,4 line 217214: p:com.example.mimiryen.project,10,7506 line 217215: a:com.example.mimiryen.project.mainactivity,10,0,0,0,0,0,0,0,0,0,0 line 217307: p:com.example.mimiryen.project,26,637650 line 217308: a:com.example.mimiryen.project.mainactivity,26,0,0,0,1,1,2,7,3,0,5 line 217405: p:com.example.mimiryen.project,51,1781435 line 217406: a:com.example.mimiryen.project.mainactivity,51,5,5,1,7,4,4,3,1,0,0 line 217502: p:com.example.mimiryen.project,16,584423 line 217503: a:com.example.mimiryen.project.mainactivity,16,0,0,0,1,4,2,3,1,1,0 line 219016: interval effective/min/max 5/5/5[s] duration: 6[minutes] client: worksource{10706 com.example.mimiryen.project} tag: fused.nlpcontroller:nlpfullpower lowpower: false num requests: 15 active: false line 219017: interval effective/min/max 5/5/5[s] duration: 1[minutes] client: worksource{10705 com.example.mimiryen.project} tag: fused.nlpcontroller:nlpfullpower lowpower: false num requests: 3 active: false line 219028: interval effective/min/max 30/30/30[s] duration: 6[minutes] client: worksource{10706 com.example.mimiryen.project} tag: fused.nlpcontroller:ar num requests: 15 active: false line 219029: interval effective/min/max 30/30/30[s] duration: 1[minutes] client: worksource{10705 com.example.mimiryen.project} tag: fused.nlpcontroller:ar num requests: 3 active: false line 219393: interval effective/min/max 5/5/5[s] duration: 7[minutes] [com.example.mimiryen.project, priority_high_accuracy] num requests: 17 active: false line 219437: 05-25 09:41:23: removed location request [10706:com.example.mimiryen.project] line 219442: 05-25 09:41:21: added location request [10706:com.example.mimiryen.project]
Comments
Post a Comment