android - gps app reverse geocoding error -


im trying change code reverse geocoding well. coordinates work fine. im gettin error: location cannot resolved variable. error @ line of code:

list<address> addresses = geocoder.getfromlocation(location.getlatitude,     location.getlongitude, 1);  

my full code is:

package gps.attempt;     import java.io.ioexception;    import java.util.list;    import java.util.locale;     import android.app.activity;    import android.content.intent;    import android.location.address;    import android.location.location;    import android.location.geocoder;    import android.location.locationlistener;    import android.location.locationmanager;    import android.location.locationprovider;    import android.os.bundle;    import android.util.log;    import android.widget.textview;    import android.widget.toast;     public class gpsattemptactivity extends activity implements locationlistener {  /* class implements locationlistener, listens both  * changes in location of device , changes in status  * of gps system.  * */  static final string tag = "main"; // log  textview txtinfo; locationmanager lm; stringbuilder sb; int nooffixes = 0;  /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      /* textview display gps data */     txtinfo = (textview) findviewbyid(r.id.textview1);     textview myaddress = (textview)findviewbyid(r.id.myaddress);      /* location manager vital part allows access      * location , gps status services */     lm = (locationmanager) getsystemservice(location_service);         geocoder geocoder = new geocoder(this, locale.english);         try {   list<address> addresses = geocoder.getfromlocation(location.getlatitude, location.getlongitude, 1);    if(addresses != null) {    address returnedaddress = addresses.get(0);    stringbuilder strreturnedaddress = new stringbuilder("address:\n");    for(int i=0; i<returnedaddress.getmaxaddresslineindex(); i++) {     strreturnedaddress.append(returnedaddress.getaddressline(i)).append("\n");    }    myaddress.settext(strreturnedaddress.tostring());   }   else{    myaddress.settext("no address returned!");   }  } catch (ioexception e) {   // todo auto-generated catch block   e.printstacktrace();   myaddress.settext("cannot address!");  }  }     @override protected void onresume() {     /*      * onresume is called after onstart, if app hasn't been      * paused      *      * add location listener , request updates every 1000ms or 10m      */     lm.requestlocationupdates(locationmanager.gps_provider, 1000, 10f, this);     super.onresume(); }  @override protected void onpause() {     /* gps, turns out, consumes battery crazy */     lm.removeupdates(this);     super.onpause(); }  @override public void onlocationchanged(location location) {     log.v(tag, "location changed");      sb = new stringbuilder(512);      nooffixes++;      /* display of data in textview */      sb.append("no. of fixes: ");     sb.append(nooffixes);     sb.append('\n');     sb.append('\n');      sb.append("longitude: ");     sb.append(location.getlongitude());     sb.append('\n');      sb.append("latitude: ");     sb.append(location.getlatitude());     sb.append('\n');      sb.append("accuracy: ");     sb.append(location.getaccuracy());     sb.append('\n');       txtinfo.settext(sb.tostring()); }  @override public void onproviderdisabled(string provider) {     /* called if/when gps disabled in settings */     log.v(tag, "disabled");      /* bring gps settings */     intent intent = new intent(             android.provider.settings.action_location_source_settings);     startactivity(intent); }  @override public void onproviderenabled(string provider) {     log.v(tag, "enabled");     toast.maketext(this, "gps enabled", toast.length_short).show();  }  @override public void onstatuschanged(string provider, int status, bundle extras) {     /* called when gps status alters */     switch (status) {     case locationprovider.out_of_service:         log.v(tag, "status changed: out of service");         toast.maketext(this, "status changed: out of service",                 toast.length_short).show();         break;     case locationprovider.temporarily_unavailable:         log.v(tag, "status changed: temporarily unavailable");         toast.maketext(this, "status changed: temporarily unavailable",                 toast.length_short).show();         break;     case locationprovider.available:         log.v(tag, "status changed: available");         toast.maketext(this, "status changed: available",                 toast.length_short).show();         break;     } }  @override protected void onstop() {     /* may finish since saving state not important toy app */     finish();     super.onstop(); }   } 

manifest:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="gps.attempt" android:versioncode="1" android:versionname="1.0" >  <uses-sdk android:minsdkversion="8" />  <uses-permission android:name="android.permission.internet"></uses-permission>  <application     android:icon="@drawable/ic_launcher"     android:label="@string/app_name" >     <activity         android:name=".gpsattemptactivity"         android:label="@string/app_name" >         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity> </application>      <uses-permission android:name="android.permission.access_fine_location" /> <uses-permission android:name="android.permission.access_mock_location" /> <uses-permission android:name="android.permission.access_coarse_location" /> <uses-permission android:name="android.permission.access_location_extra_commands" /> <uses-permission android:name="android.permission.control_location_updates" /> 

i grateful if me

have @ answer here it's similar question using different sensor.

you making (understandable) mistake of assuming can location instantly on phone. can't unfortunately. have start service , wait come when has location fix.

if want instant location can see if call getlastknowlocation() non-null (but may inaccurate) , use that. otherwise need put geocoding logic in onlocationchanged() method , wait called.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -