android - Dynamic markers on a map? -
how dynamically draw markers on mapview? i've got following code hardcode 1 point in. i'm looking pull values database..
//---translate geopoint screen pixels--- point screenpts = new point(); mapview.getprojection().topixels(p, screenpts); //---add marker--- bitmap bmp = bitmapfactory.decoderesource( getresources(), r.drawable.pushpin); canvas.drawbitmap(bmp, screenpts.x, screenpts.y-50, null);
i've got locations in database. how not declare point variable etc. each point exists in database table of size n?
thanks.
write overlaycalss implements itemizedoverlay .this better method implementing multiple markers. can add amrkers fetched database :
db = sqlitedatabase.opendatabase(
"/data/data/<your project package>/databases/<databasename>", null, 0); cursor = db.query(<db table name>, new string[] { <values fetch> }, null, null, null, null, null); cursor.movetofirst(); //log.i("log", "displaying markers through iteration"); while (cursor.isafterlast() == false) { lat = double.parsedouble(cursor.getstring(2)); lng = double.parsedouble(cursor.getstring(3)); // log.i("points", lat + " " + lng); point = new geopoint((int) (lat * 1e6), (int) (lng * 1e6)); overlayitem = new overlayitem(point, "", ""); overlays.addoverlay(overlayitem); mapoverlays.add(overlays); cursor.movetonext(); } db.close();
where overlays instance of overlaycalss extends itemizedoverlay , mapoverlays list of overlay items . included log files debugging purposes...decalre variables used in file ...
hope helps ... :)
Comments
Post a Comment