>
> You have not requested location updates, so getLastKnownLocation()
> will always return null.

Also, getLastKnownLocation() will almost never have a value immediately, as
> it takes GPS some time to obtain a fix.


Hey Mark, is this right?
I thought the whole point of getLastKnownLocation() was to get an immediate
value while the LocationManager got the real fix?

To the OP: According to the docs this function returns null if the selected
provider is disabled, so make sure you have GPS enabled on your phone when
you try it.

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
http://sites.google.com/site/rezmobileapps/treking


On Mon, Jan 11, 2010 at 10:14 AM, Mark Murphy <[email protected]>wrote:

> RamaMohan wrote:
> > Hi all,
> > I have the problem like this.
> > Basically i want to find my present location's latitude and
> > longitude .It is showing in emulator which is default one which points
> > to Sanjose,usa.But it is not finding my current location(i am in
> > Hyderabad,India).When i try to run the same application in My HTC
> > magic (Android os 1.5) it is showing NULL.It is Not finding my present
> > location.
> > What i have to do..is there need of Network provider like Mobile
> > network(Vodafone,airtel etc..)
> > I am sending my code,Please check it and send me the working code if
> > any body have,Please i need it urgently.
> > Please Help me regarding this.
> > Thanks,
> > Ram.P
> > the code is as follows:
> > ------------------------------------------------------------------------
> > class WhereAmI extends Activity {
> >
> >   @Override
> >   public void onCreate(Bundle icicle) {
> >     super.onCreate(icicle);
> >     setContentView(R.layout.main);
> >
> >     LocationManager locationManager;
> >     locationManager = (LocationManager)getSystemService
> > (Context.LOCATION_SERVICE);
> >     Location location = locationManager.getLastKnownLocation
> > (LocationManager.GPS_PROVIDER);
> >
> >     updateWithNewLocation(location);
> >   }
> >
> >   /** Update UI with a new location */
> >   private void updateWithNewLocation(Location location) {
> >         TextView myLocationText = (TextView)findViewById
> > (R.id.myLocationText);
> >
> >         String latLongString;
> >
> >     if (location != null) {
> >           double lat = location.getLatitude();
> >           double lng = location.getLongitude();
> >           latLongString = "Lat:" + lat + "\nLong:" + lng;
> >         } else {
> >           latLongString = "No location found";
> >         }
> >
> >         myLocationText.setText("Your Current Position is:\n" +
> > latLongString);
> >       }
> >
> > }
> > -----------------------------------------
> > Manifest file is as follows:
> >
> > ----------------
> > <manifest xmlns:android="http://schemas.android.com/apk/res/android";
> > package="com.paad.whereami">
> >   <application android:icon="@drawable/icon">
> >     <activity android:name=".GPS" 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"/>
> > </manifest>
> >
> > --------------------------------------
> >
> > Please help me very urgently.......
>
> You have not requested location updates, so getLastKnownLocation() will
> always return null.
>
> Also, getLastKnownLocation() will almost never have a value immediately,
> as it takes GPS some time to obtain a fix.
>
> --
> Mark Murphy (a Commons Guy)
> http://commonsware.com | http://twitter.com/commonsguy
>
> Android Consulting/App Development: http://commonsware.com/consulting
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to