How do i show the marker at given position on google map in android? -
i developing app using google map.in want show marker @ location longitude latitude values fetch form server.how show marker @ fetched longitude , latitude value? following code fetch longitude , latitude values server successfully, want show marker on google map fetch langitude , latitude.how do?
//java code public class location_track1 extends activity { private static final string tag = "location_track1"; private static final long interval = 1000 * 60 * 1; //1 minute private static final long fastest_interval = 1000 * 60 * 1; // 1 minute private static final float smallest_displacement = 0.25f; //quarter of meter button btnfusedlocation; textview tvlocation; locationrequest mlocationrequest; googleapiclient mgoogleapiclient; location mcurrentlocation; string mlastupdatetime; googlemap googlemap; private imageview mcurrentpointer; private double longitude; private double latitude; // private arraylist<latlng> points; //added private list<latlng> points = new arraylist<>(); polyline line; //added textview tv_mobno, tv_latitude, tv_longitude, tv_time; string getlatitude; string getlongitude; button slocation; jsonarray result = null; progressdialog mprogressdialog; arraylist<hashmap<string, string>> arraylist; static string con = "con"; jsonobject jsonobject; jsonarray jsonarray; private string url =""; private static final string tag_user = "result"; // private static final string tag_sname = "pseats"; private static final string tag_long = "longitude"; private static final string tag_lat = "latitude"; private static final string tag_address = "paddress"; protected void createlocationrequest() { mlocationrequest = new locationrequest(); mlocationrequest.setinterval(interval); mlocationrequest.setfastestinterval(fastest_interval); mlocationrequest.setsmallestdisplacement(smallest_displacement); //added mlocationrequest.setpriority(locationrequest.priority_high_accuracy); } @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.location_track); log.d(tag, "oncreate ..............................."); tv_mobno=(textview)findviewbyid(r.id.textview_mob); tv_latitude=(textview)findviewbyid(r.id.textview_latitude); tv_longitude=(textview)findviewbyid(r.id.textview_longitude); tv_time=(textview)findviewbyid(r.id.textview_time); slocation=(button)findviewbyid(r.id.button_slocation); url = "http://example.in/gmap_track.php"; // points = new arraylist<latlng>(); googlemap = ((mapfragment) getfragmentmanager().findfragmentbyid(r.id.map)) .getmap(); slocation.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // new downloadjson().execute(); new jsonparse().execute(); } }); } private class jsonparse extends asynctask<string, string, jsonobject> { private progressdialog pdialog; @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(location_track1.this); pdialog.setmessage("getting data ..."); pdialog.setindeterminate(false); pdialog.setcancelable(true); pdialog.show(); } @override protected jsonobject doinbackground(string... args) { jsonparser jparser = new jsonparser(); // getting json url jsonobject json = jparser.getjsonfromurl(url); return json; } @override protected void onpostexecute(jsonobject json) { pdialog.dismiss(); try { // getting json array result = json.getjsonarray(tag_user); jsonobject c = result.getjsonobject(0); // storing json item in variable string lat = c.getstring(tag_lat); string longt = c.getstring(tag_long); //set json data in textview tv_latitude.settext(lat); tv_longitude.settext(longt); /* double lat = c.getdouble(tag_lat); double longt = c.getdouble(tag_long); markeroptions marker = new markeroptions().position(new latlng(lat, longt)).title("point"); googlemap.addmarker(marker);*/ } catch (jsonexception e) { e.printstacktrace(); } } } }
why commented out code adding marker? try :
// storing json item in variable string lat = c.getstring(tag_lat); string longt = c.getstring(tag_long); //set json data in textview tv_latitude.settext(lat); tv_longitude.settext(longt); //parse data double double latd = double.parsedouble(lat); double longtd = double.parsedouble(longt); markeroptions marker = new markeroptions().position(new latlng(latd, longtd)).title("point"); googlemap.addmarker(marker);
Comments
Post a Comment