Location-based alert using SQLite Android error force close -
i updated last post make location-based alert using sqlite database.. problem different, when try view map using location-based service function force close.
this query code
public boolean postcheck(string addr) { openconn(); cursor cur = db.rawquery("select * " + tablename + " " + alamat + " = " + addr, null); if (cur != null) { if(cur.getcount() > 0) { return true; } } closeconn(); return false; }
then put query on location listener class
class mylocationlistener implements locationlistener { //cek untuk lokasi pengguna @override public void onlocationchanged(location location) { if (location != null) { locmanager.removeupdates(loclistener); navigatetolocation(location.getlatitude(), location.getlongitude()); //cek tugas txtaddr = teksalamat.gettext().tostring(); toast.maketext(getapplicationcontext(), txtaddr, toast.length_long).show(); if (txtaddr.length() > 0) { if (dbhandler.postcheck(txtaddr)) { toast.maketext(getapplicationcontext(), "anda ada tugas di lokasi " + txtaddr, toast.length_long).show(); } else { toast.maketext(getapplicationcontext(), "anda tidak ada tugas di lokasi sekarang", toast.length_long).show(); } } } else { system.out.println("cek lokasi = null"); } }
and navigatetolocation function
public void navigatetolocation(double latitude, double longitude) { geopoint p = new geopoint((int) (latitude * 1e6), (int) (1e6 * longitude)); userlat = p.getlatitudee6(); userlon = p.getlongitudee6(); //menggambar penanda lokasi list<overlay> mapoverlay = mapview.getoverlays(); drawable draw = this.getresources().getdrawable(r.drawable.map_pin); mapmarker mapmarker = new mapmarker(draw, this); overlayitem overlayitem = new overlayitem(p, "", "posisi anda sekarang"); mapmarker.addoverlay(overlayitem); mapoverlay.add(mapmarker); alamat = converttoaddress(p); teksalamat.settext(alamat); //tampilkan lokasi pengguna mapcontrol.animateto(p); toast.maketext(getapplicationcontext(), "lokasi anda " + alamat + "\n" + "lat = " + userlat + "\n" + "long = " + userlon, toast.length_long).show(); }
then function check location
private void ceklokasi() { //cek koneksi try { gps_enabled = locmanager.isproviderenabled(locationmanager.gps_provider); } catch (exception ex) { // todo: handle exception } try { network_enabled = locmanager.isproviderenabled(locationmanager.network_provider); } catch (exception ex) { // todo: handle exception } if(!gps_enabled && !network_enabled) { toast.maketext(getbasecontext(), "gps dan jaringan provider tidak tersedia", toast.length_short).show(); } else if(gps_enabled) { toast.maketext(getbasecontext(), "menggunakan gps", toast.length_short).show(); locmanager.requestlocationupdates(locationmanager.gps_provider, 0, 0, loclistener); } else if(network_enabled) { toast.maketext(getbasecontext(), "menggunakan jaringan non gps", toast.length_short).show(); locmanager.requestlocationupdates(locationmanager.network_provider, 0, 0, loclistener); } }
i put function ceklokasi() on function oncreate using thread
//thread untuk menjalankan lbs timer = new timer(); timer.schedule(new timertask() { handler handlerlokasi = new handler(looper.getmainlooper()); @override public void run() { // todo auto-generated method stub handlerlokasi.post(new runnable() { @override public void run() { // todo auto-generated method stub ceklokasi(); } }); } }, 0, 300000);
please me check this, got stuck @ part..
Comments
Post a Comment