android - How to display markers from sqlite on OpenStreetMap -


i'm creating application sqlite database , openstreetmap. in db i've store data id, type of building, year, function, latitude , longitude. i'm trying display on openstreetmap markers db , 1 marker current gps position. @ moment @ map displaying location , first record db. how can display markers on map? p.s. tried using various examples found in google

my mapa class

public class mapa extends activity implements locationlistener { private mapview osm; private mapcontroller mc; private locationmanager locationmanager; wywiaddata wywiaddata; int id_marker; double dlugosc; double szerokosc;   @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.map_view);      osm = (mapview) findviewbyid(r.id.mapview);     final float scale = getbasecontext().getresources().getdisplaymetrics().density;     final int newscale = (int) (256 * scale);     string[] osmsource = new string[2];     osmsource[0] = "http://a.tile.openstreetmap.org/";     osmsource[1] = "http://b.tile.openstreetmap.org/";     xytilesource mapsource = new xytilesource("osm", null, 1, 18, newscale, ".png", osmsource);     osm.settilesource(mapsource);     osm.setbuiltinzoomcontrols(true);     osm.setmultitouchcontrols(true);     osm.setmaxzoomlevel(18);     osm.setminzoomlevel(1);     mc = (mapcontroller) osm.getcontroller();     mc.setzoom(18);     geopoint center = new geopoint(50.2586, 19.0223);     mc.animateto(center);     wywiaddata = new wywiaddata(this, null, null, 1);     cursor cursor = wywiaddata.getmarkers();     double dlq = cursor.getdouble(cursor.getcolumnindexorthrow("dlugosc"));     double szr = cursor.getdouble(cursor.getcolumnindexorthrow("szerokosc"));     id_marker = cursor.getint(cursor.getcolumnindexorthrow("_id"));     dlugosc = double.valueof(dlq);     szerokosc = double.valueof(szr);       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) {         // todo: consider calling         return;     }     locationmanager.requestlocationupdates(locationmanager.gps_provider, 0, 0, this); }  @targetapi(build.version_codes.jelly_bean_mr2) public void addmarker(geopoint center) {     marker marker = new marker(osm);     marker.setposition(center);     marker marker2 = new marker(osm);     marker.setanchor(marker.anchor_center, marker.anchor_bottom);     geopoint center2 = new geopoint(dlugosc, szerokosc);     marker2.setposition(center2);     marker2.setanchor(marker.anchor_center, marker.anchor_bottom);     osm.getoverlays().add(marker);     osm.getoverlays().add(marker2); }   @targetapi(build.version_codes.jelly_bean_mr2) @override public void onlocationchanged(location location) {     geopoint center = new geopoint(location.getlatitude(), location.getlongitude());     mc.animateto(center);     osm.getoverlays().clear();     addmarker(center);     osm.invalidate();  }  @override public void onstatuschanged(string provider, int status, bundle extras) {  }  @override public void onproviderenabled(string provider) {  }  @override public void onproviderdisabled(string provider) {  } } 

and db class:

public class wywiaddata extends sqliteopenhelper { public static final string data_base_name = "wywiad.db"; public static final int data_base_version = 1; public final static string tag = "wywiad data";  public wywiaddata(context context, object o, object o1, int i) {     super(context, data_base_name, null, data_base_version); }  public void oncreate(sqlitedatabase db) {     db.execsql("create table " + tabela.table_name + " ( " + tabela._id + " integer primary key autoincrement, " + tabela.operator + " text, " + tabela.funkcja + " text, " + tabela.kod_funkcji + " text, " + tabela.material + " text, " + tabela.rok + " integer, " + tabela.zrodlo + " text, " + tabela.kond_nadz + " integer, " + tabela.kond_podz + " integer, " + tabela.status + " text, " + tabela.dlugosc + " text, " + tabela.szerokosc + " text, " + tabela.data + " text, " + tabela.uwagi + " text" + ")"); }  @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {     db.execsql("drop table if exists " + tabela.table_name);     oncreate(db); }  public boolean insertdata(string operator, string funkcja, string kod, string material, string rok, string zrodlo, string kond_nadz, string kond_podz, string status, string datadodania, double dlugosc, double szerkosc, string uwagi) {     sqlitedatabase db = this.getwritabledatabase();     contentvalues contentvalues = new contentvalues();     contentvalues.put(tabela.operator, operator);     contentvalues.put(tabela.funkcja, funkcja);     contentvalues.put(tabela.kod_funkcji, kod);     contentvalues.put(tabela.material, material);     contentvalues.put(tabela.rok, rok);     contentvalues.put(tabela.zrodlo, zrodlo);     contentvalues.put(tabela.kond_nadz, kond_nadz);     contentvalues.put(tabela.kond_podz, kond_podz);     contentvalues.put(tabela.status, status);     contentvalues.put(tabela.data, datadodania);     contentvalues.put(tabela.dlugosc, dlugosc);     contentvalues.put(tabela.szerokosc, szerkosc);     contentvalues.put(tabela.uwagi, uwagi);     long result = db.insert(tabela.table_name, null, contentvalues);     if (result == -1) {         return false;     } else {         return true;     } }  public cursor getlistcontents() {     sqlitedatabase db = this.getwritabledatabase();     cursor data = db.rawquery(" select * " + tabela.table_name, null);     return data; }   public cursor getitemid(int id) {     sqlitedatabase db = this.getwritabledatabase();     string query = " select * " + tabela.table_name + " " + tabela._id + " = '" + id + "'";     cursor cursor = db.rawquery(query, null);     if (cursor != null) {         cursor.movetofirst();      }     log.e("wywiad", "zwrócono po id: " + cursor);     return cursor; }   public void updatedata(lista lista) {     sqlitedatabase db = this.getwritabledatabase();     contentvalues contentvalues = new contentvalues();     contentvalues.put(tabela.operator, lista.getoperator());     contentvalues.put(tabela.funkcja, lista.getfunkcja());     contentvalues.put(tabela.kod_funkcji, lista.getkod());     contentvalues.put(tabela.material, lista.getmaterial());     contentvalues.put(tabela.rok, lista.getrok());     contentvalues.put(tabela.zrodlo, lista.getzrodlo());     contentvalues.put(tabela.kond_nadz, lista.getkondygnacje_nad());     contentvalues.put(tabela.kond_podz, lista.getkondygnacje_pod());     contentvalues.put(tabela.status, lista.getstatus());     contentvalues.put(tabela.uwagi, lista.getuwagi());     db.update(tabela.table_name, contentvalues, tabela._id + "=?", new string[]{string.valueof(lista.getidentyfikator())});     db.close();  }  public void deletedata(int id) {     sqlitedatabase db = this.getwritabledatabase();     string query = " delete " + tabela.table_name + " " + tabela._id + " = '" + id + "'";     db.execsql(query); }  public cursor getmarkers() {     sqlitedatabase db = this.getwritabledatabase();     cursor cursor = db.rawquery(" select * " + tabela.table_name, null);     if (cursor != null) {         cursor.movetofirst();      }     return cursor; } } 

you don't create marker, want define characteristics of marker using markeroptions , add map

public void addmarker(geopoint center) {     markeroptions options = new markeroptions();     marker marker = new marker(osm);     options.position(center);     options.anchor( marker.anchor_center, marker.anchor_bottom);      marker marker = osm.addmarker(options); } 

edit add sqlite

try {     while (cursor.movetonext()) {         geopoint point = new geopoint(cursor.getlong("lat"), cursor.getlong("lng"));         addmarker(point);     } } {     cursor.close(); } 

this iterate through of objects in cursor, create geopoint , pass addmarker method


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -