java - Having difficulties while passing location from GPS to web service -
i'm creating android application current position , pass web service. have no errors now, problem can't pass location web service.
here's code, if know problem kindly point out me please passing part on phpconnect class.
**
public class mapping extends mapactivity { private mapview mapview; private mapcontroller mapcontroller; private locationmanager locationmanager; private locationlistener locationlistener; // ** declarations passing of data web service // progress dialog private progressdialog pdialog; // jsonparser object creation jsonparser jsonparser = new jsonparser(); // url pass location web private static string url_create_product = "http://student-thesis.netii.net/location_adding.php"; //private static string url_create_product = "http://10.0.2.2/thecalling/location_adding.php"; // json node names private static final string tag_success = "success"; //latitude , longitude public static double ilatitude; public static double ilongitude; // ** end @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.maps2); mapview = (mapview) findviewbyid(r.id.mapview); // enable show satellite view mapview.setsatellite(true); // enable show traffic on map mapview.settraffic(true); mapview.setbuiltinzoomcontrols(true); mapcontroller = mapview.getcontroller(); mapcontroller.setzoom(16); locationmanager = (locationmanager) getsystemservice(context.location_service); locationlistener = new gpslocationlistener(); locationmanager.requestlocationupdates(locationmanager.gps_provider, 25000, 5, locationlistener); } private class gpslocationlistener implements locationlistener { @override public void onlocationchanged(location location) { // todo auto-generated method stub if (location != null) { ilatitude = (int)(location.getlatitude() * 1e6); ilongitude = (int)(location.getlongitude() * 1e6); geopoint point = new geopoint( (int) (ilatitude), (int) (ilongitude)); toast.maketext( getbasecontext(), "latitude: " + location.getlatitude() + " longitude: " + location.getlongitude(), toast.length_long) .show(); // add marker mapoverlay mapoverlay = new mapoverlay(); mapoverlay.setpointtodraw(point); list<overlay> listofoverlays = mapview.getoverlays(); listofoverlays.clear(); listofoverlays.add(mapoverlay); string address = convertpointtolocation(point); toast.maketext(getbasecontext(), address, toast.length_long).show(); mapcontroller.animateto(point); mapcontroller.setzoom(16); mapview.invalidate(); new phpconnect().execute(); } } @override public void onproviderdisabled(string provider) { // todo auto-generated method stub } @override public void onproviderenabled(string provider) { // todo auto-generated method stub } @override public void onstatuschanged(string provider, int status, bundle extras) { // todo auto-generated method stub } } class mapoverlay extends overlay { private geopoint pointtodraw; public void setpointtodraw(geopoint point) { pointtodraw = point; } public geopoint getpointtodraw() { return pointtodraw; } @override public boolean draw(canvas canvas, mapview mapview, boolean shadow, long when) { super.draw(canvas, mapview, shadow); // convert point pixels point screenpts = new point(); mapview.getprojection().topixels(pointtodraw, screenpts); // add marker bitmap bmp = bitmapfactory.decoderesource(getresources(), r.drawable.reddot); canvas.drawbitmap(bmp, screenpts.x, screenpts.y - 24, null); return true; } } class phpconnect extends asynctask<string, string, string> { @override protected string doinbackground(string... args) { string strlatitude = double.tostring(ilatitude); string strlongitude = double.tostring(ilongitude); // building parameters list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair("latitude", strlatitude)); params.add(new basicnamevaluepair("longitude", strlongitude)); // getting json object // note create product url accepts post method jsonobject json = jsonparser.makehttprequest(url_create_product, "post", params); // check log cat fro response log.d("create response", json.tostring()); try { int success = json.getint(tag_success); if (success == 1) { // updated locationlistener = new gpslocationlistener(); } else { // failed create product } } catch (jsonexception e) { e.printstacktrace(); } return null; } } public string convertpointtolocation(geopoint point) { string address = ""; geocoder geocoder = new geocoder( getbasecontext(), locale.getdefault()); try { list<address> addresses = geocoder.getfromlocation( point.getlatitudee6() / 1e6, point.getlongitudee6() / 1e6, 1); if (addresses.size() > 0) { (int index = 0; index < addresses.get(0).getmaxaddresslineindex(); index++) address += addresses.get(0).getaddressline(index) + " "; } } catch (ioexception e) { e.printstacktrace(); } return address; } @override protected boolean isroutedisplayed() { // todo auto-generated method stub return false; } }
**
and web code:
**
<?php $latitude=($_post['latitude']); $longitude=($_post['longitude']); $response = array(); if(isset($_post['latitude']) && isset($_post['longitude'])){ mysql_connect("xxxxxxx", "xxxxxxxx", "xxxxxxx" ) or die("could not find!"); mysql_select_db("xxxxxxx") or die("database not exist!"); $pid = 3; $result = mysql_query("update users set latitude = '$latitude', longitude = '$longitude', id=$pid"); if ($result) { // updated $response["success"] = 1; $response["message"] = "user information updated."; // echoing json response echo json_encode($response); } else { } } else { // required field missing $response["success"] = 0; $response["message"] = "required field(s) missing"; // echoing json response echo json_encode($response); } ?>
**
thanks guys in advance. :)
Comments
Post a Comment