php - Google Maps Android app with multiple users' location -
i attempting make app multiple users send current location remote mysql database , each user can pull lat, long coords see users on map. problem having @ moment when try send location mysql database app crashes. appreciated. here java activity:
package com.paul.locations; import java.text.simpledateformat; import java.util.arraylist; import java.util.calendar; import java.util.list; import org.apache.http.namevaluepair; import org.apache.http.message.basicnamevaluepair; import org.json.jsonexception; import org.json.jsonobject; import com.paul.locations.jsonparser; import com.paul.locations.r; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.mapfragment; import android.location.locationmanager; import android.os.asynctask; import android.os.bundle; import android.app.activity; import android.app.progressdialog; import android.content.context; import android.util.log; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; public class location extends activity implements onclicklistener { private googlemap googlemap; private string lat="", lon="", current = ""; private button bload, bstore; // progress dialog private progressdialog pdialog; // json parser class jsonparser jsonparser = new jsonparser(); //php add comment script //localhost : //testing on device //put local ip instead, on windows, run cmd > ipconfig //or in mac's terminal type ifconfig , ip under en0 or en1 private static final string load_info_url = "http://192.168.1.14/locations/load_info.php"; private static final string update_info_url = "http://192.168.1.14/locations/update_info.php"; //testing on emulator: //private static final string post_comment_url = "http://10.0.2.2:1234/webservice/addcomment.php"; //testing real server: //private static final string post_comment_url = "http://www.mybringback.com/webservice/addcomment.php"; //ids private static final string tag_success = "success"; private static final string tag_message = "message"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.map); setupmap(); bload = (button)findviewbyid(r.id.bload); bload.setonclicklistener(this); bstore = (button)findviewbyid(r.id.bstore); bstore.setonclicklistener(this); } @override public void onclick(view v) { // todo auto-generated method stub switch (v.getid()) { case r.id.bload: new attemptload().execute(); break; case r.id.bstore: locationmanager lm = (locationmanager)getsystemservice(context.location_service); android.location.location location = lm.getlastknownlocation(locationmanager.gps_provider); lon = double.tostring(location.getlongitude()); lat = double.tostring(location.getlatitude()); system.out.println(lon + ", " + lat); calendar c = calendar.getinstance(); simpledateformat df = new simpledateformat("hh:mm:ss"); current = df.format(c.gettime()); system.out.println(current); new attemptstore().execute(); break; default: break; } } class attemptload extends asynctask<string, string, string> { @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(location.this); pdialog.setmessage("attempting load locations..."); pdialog.setindeterminate(false); pdialog.setcancelable(true); pdialog.show(); } @override protected string doinbackground(string... params) { // todo auto-generated method stub return null; } } class attemptstore extends asynctask<string, string, string> { @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(location.this); pdialog.setmessage("attempting store location..."); pdialog.setindeterminate(false); pdialog.setcancelable(true); pdialog.show(); } @override protected string doinbackground(string... args) { // todo auto-generated method stub string success; try { // building parameters list<namevaluepair> params1 = new arraylist<namevaluepair>(); params1.add(new basicnamevaluepair("lat", lat)); params1.add(new basicnamevaluepair("lon", lon)); params1.add(new basicnamevaluepair("time", current)); log.d("request!", "starting"); //posting user data script jsonobject json = jsonparser.makehttprequest( update_info_url, "post", params1); // full json response log.d("store location attempt", json.tostring()); // json success element success = json.getstring(tag_success); if(success.equals("success")) { log.d("location stored!", json.tostring()); finish(); return json.getstring(tag_message); }else{ log.d("storing location failure!", json.getstring(tag_message)); return json.getstring(tag_message); } } catch (jsonexception e) { e.printstacktrace(); } return null; } protected void onpostexecute(string file_url) { // dismiss dialog once product deleted pdialog.dismiss(); //if (file_url != null){ //toast.maketext(location.this, file_url, toast.length_long).show(); //} } } private void setupmap() { if(googlemap == null){ googlemap = ((mapfragment)getfragmentmanager().findfragmentbyid(r.id.map)).getmap(); if(googlemap != null){ //code initialize map googlemap.setmylocationenabled(true); } } } }
i error occurring in "attempt store" class clicking on bstore button creates error
this logcat:
07-31 13:27:40.245: d/sensormanager(30830): unregisterlistener:: listener= android.view.orientationeventlistener$sensoreventlistenerimpl@41d55290 07-31 13:27:40.245: i/sensormanager(30830): set normal delay = true 07-31 13:27:40.245: d/sensormanager(30830): registerlistener :: handle = 4 name= mpl accel delay= 200000 listener= android.view.orientationeventlistener$sensoreventlistenerimpl@41d58410 07-31 13:27:40.255: w/iinputconnectionwrapper(30830): getselectedtext on inactive inputconnection 07-31 13:27:40.265: w/iinputconnectionwrapper(30830): setcomposingtext on inactive inputconnection 07-31 13:27:43.779: d/request!(30830): starting 07-31 13:27:43.799: i/adreno200-eglsub(30830): <configwindowmatch:2087>: format rgba_8888. 07-31 13:27:43.829: d/sensormanager(30830): unregisterlistener:: listener= android.view.orientationeventlistener$sensoreventlistenerimpl@41d58410 07-31 13:27:43.829: i/sensormanager(30830): set normal delay = true 07-31 13:27:45.241: d/login attempt(30830): {"message":"login successful!","success":1} 07-31 13:27:45.241: d/login successful!(30830): {"message":"login successful!","success":1} 07-31 13:27:45.661: d/abslistview(30830): motionrecognitionmanager 07-31 13:27:45.771: i/adreno200-eglsub(30830): <configwindowmatch:2087>: format rgba_8888. 07-31 13:27:45.801: i/adreno200-eglsub(30830): <configwindowmatch:2098>: format rgbx_8888. 07-31 13:27:45.961: w/iinputconnectionwrapper(30830): getselectedtext on inactive inputconnection 07-31 13:27:45.961: w/iinputconnectionwrapper(30830): setcomposingtext on inactive inputconnection 07-31 13:27:49.765: i/system.out(30830): -117.21201925, 32.75091863 07-31 13:27:49.765: i/system.out(30830): 13:27:49 07-31 13:27:49.796: d/request!(30830): starting 07-31 13:27:49.816: i/adreno200-eglsub(30830): <configwindowmatch:2087>: format rgba_8888. 07-31 13:27:50.987: e/json parser(30830): error parsing data org.json.jsonexception: value <br of type java.lang.string cannot converted jsonobject 07-31 13:27:50.987: d/store location attempt(30830): {"message":"login successful!","success":1} 07-31 13:27:50.987: d/storing location failure!(30830): login successful!
the error json parser cannot parse data. know php scripts correct because can send , receive data loading them in browser. super cool
thanks!
have check json format
you have error
error parsing data org.json.jsonexception: value
so check in response json object or json array ?
Comments
Post a Comment