Sorry Wrong Code...
Use this in the quote...
Also it will be the best accurracy with in 5 Minutes else the Newest..
SORRY for the messup
Kim
On Wednesday, June 22, 2011 12:03:09 PM UTC+2, Kim Ras wrote:
>
> Hi,
> You should use the getLastKnownLocation.. It will return the last
> location from any of the Location providers..
> I have build a Method (Based on some initial code from the Forums) to
> get the best and most precise Location (Less than 10meters),
> It will look through all Location provides and get the most accurate
> Locating with in 5 Minutes, if that do not exists then get the newest
> (Normally the Network Location)..
>
> You will need to change the oLog.txt call to Log.v or remove them.. I
> have another logging system in my projects.
>
> /
> ************************************************************************************************************
>
>
> *
> * This is a fast code to get the last known location of the
> phone. It will first attempt to get the most
> * accurate position the last 5 minutes. If that is not available
> then it will get the newest location.
> *
>
> *************************************************************************************************************/
>
>
> private static final int FIVE_MINUTES = 1000 * 60 * 5;
> private String[] getLastGoodPos() {
> LocationManager lm = (LocationManager)
> getSystemService(Context.LOCATION_SERVICE);
> List<String> providers = lm.getProviders(true);
> Integer iId = -1;
> Long lTime = (long) -1;
> Long lNow = System.currentTimeMillis();
> Float fAccuracy = (float) 10000.0;
> Location l = null;
>
> // First find the best Accuracy for the last 3 minutes
> oLog.txt(5,"In good location last 5 minutes... Getting latest");
> for (int i=providers.size()-1; i>=0; i--) {
> l = lm.getLastKnownLocation(providers.get(i));
> if (l != null) {
> oLog.txt(5,"-- last good pos:" + l.toString());
>
> if (l.getTime() > lNow - FIVE_MINUTES && l.getAccuracy() <
> fAccuracy) {
> oLog.txt(5,"- Better accuracy..");
> iId = i;
> lTime = l.getTime();
> fAccuracy = l.getAccuracy();
> }
> }
> }
>
> //If no Location within 5 minutes find the newest one
> if (iId == -1) {
> oLog.txt(5,"No good location last 5 minutes... Getting latest");
> l = null;
> for (int i=providers.size()-1; i>=0; i--) {
> l = lm.getLastKnownLocation(providers.get(i));
> if (l != null) {
> oLog.txt(5,"in Get last good pos:" + l.toString());
>
> if (l.getTime() > lTime) {
> oLog.txt(5,"- Newer Location..");
> iId = i;
> lTime = l.getTime();
> fAccuracy = l.getAccuracy();
> }
> }
> }
> }
>
> //Now get the best lastKnownLocation
> String[] gps = new String[4];
>
> if (iId > -1) {
> gps[0] = "" +
> lm.getLastKnownLocation(providers.get(iId)).getLatitude();
> gps[1] = "" +
> lm.getLastKnownLocation(providers.get(iId)).getLongitude();
> gps[2] = "" +
> lm.getLastKnownLocation(providers.get(iId)).getProvider();
> gps[3] = "" +
> lm.getLastKnownLocation(providers.get(iId)).getAccuracy();
> }
> else {
> gps[0] = "";
> gps[1] = "";
> gps[2] = "";
> gps[3] = "";
> }
>
> return gps;
> }
>
> Hope it helps
> Kim
>
> On Jun 22, 11:33 am, "Md.Fazla Rabbi OPU" <[email protected]>
> wrote:
> > Hi all,
> >
> > I want to develope an app in which--> "When i start the app it will first
>
> > give me Latitude and Longitude of my current location". Here is my code:
> >
> > * LocationListener locLis=new LocationListener() {
> >
> > @Override
> > public void onStatusChanged(String provider, int status, Bundle
> extras)
> > {}
> > @Override
> > public void onProviderEnabled(String provider) {}
> > @Override
> > public void onProviderDisabled(String provider) {}
> > @Override
> > public void onLocationChanged(Location location)
> > {
> > // TODO Auto-generated method stub
> > Double lat=location.getLatitude();
> > Double lon=location.getLongitude();
> > Log.i("Latitude=="+lat,"=="+lon);
> >
> > }
> > };
> > locationManager = (LocationManager)
> > getSystemService(Context.LOCATION_SERVICE);
> > locationManager.requestLocationUpdates(
> > LocationManager.GPS_PROVIDER,0,0, locLis);*
> >
> > I use *ACCESS_FINE_LOCATION* in the manifest file.
> > But when i start the app there is no latitude and longitude it found.
> Why?
> > If i change the location's latitude longitude from the command prompt
> then
> > it will show the updated latitude and longitude. Please anyone help me
> >
> > Best Wishes
> > Md. Fazla Rabbi
--
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