This code should work. I'll note that its a bit odd to have your
Activity class implement the LocationListener, but it shouldn't make a
functional difference.

Have you tried running this code while outside? GPS generally does not
work inside buildings. The "GPS" that you refer to with Google Maps
may not actually be GPS, but rather the network location provider. If
Maps is showing a dot with a blue radius around it, this is not GPS.
In most cases GPS location on Google Maps manifests as just the dot,
although occasionally poor signal conditions result in a small radius.

So, please let me know if you're testing this code when outside.

Cheers,
Justin
Android Team @ Google

On Jan 26, 4:46 pm, octagon <[email protected]> wrote:
> Just to clarify:
>
> Is theGPSfunctionality on theG1actually supported by android at
> this time, and if so is there anexampleof it that works?
>
> On Jan 26, 6:03 pm, octagon <[email protected]> wrote:
>
> > Ah, sorry. Here it is:
>
> > Android.xml:
>
> > <?xml version="1.0" encoding="utf-8"?>
> > <manifest xmlns:android="http://schemas.android.com/apk/res/android";
> >       package="com.example"
> >       android:versionCode="1"
> >       android:versionName="1.0.0">
> >     <application android:icon="@drawable/icon" android:label="@string/
> > app_name">
> >         <activity android:name=".GPSTest"
> >                   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_COARSE_LOCATION"></uses-
> > permission>
> > <uses-permission
> > android:name="android.permission.ACCESS_FINE_LOCATION"></uses-
> > permission>
> > <uses-permission
> > android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></
> > uses-permission>
> > <uses-permission
> > android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-
> > permission>
> > <uses-permission
> > android:name="android.permission.CONTROL_LOCATION_UPDATES"></uses-
> > permission>
> > <uses-permission android:name="android.permission.INTERNET"></uses-
> > permission>
> > </manifest>
>
> > GPSTest.java:
>
> > package com.example;
>
> > import android.app.Activity;
> > import android.content.Context;
> > import android.location.Location;
> > import android.location.LocationListener;
> > import android.location.LocationManager;
> > import android.os.Bundle;
> > import android.util.Log;
>
> > public class GPSTest extends Activity implements LocationListener {
>
> >     private LocationManager lm;
>
> >     /** Called when the activity is first created. */
> >     @Override
> >     public void onCreate(Bundle savedInstanceState) {
> >         super.onCreate(savedInstanceState);
> >         setContentView(R.layout.main);
>
> >         lm = (LocationManager) getSystemService
> > (Context.LOCATION_SERVICE);
> >         lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1l,
> > 1l, this);
> >     }
>
> >         @Override
> >         public void onLocationChanged(Location arg0) {
> >                 String lat = String.valueOf(arg0.getLatitude());
> >                 String lon = String.valueOf(arg0.getLongitude());
> >                 Log.e("GPS", "location changed: lat="+lat+", lon="+lon);
> >         }
> >         public void onProviderDisabled(String arg0) {
> >                 Log.e("GPS", "provider disabled " + arg0);
> >         }
> >         public void onProviderEnabled(String arg0) {
> >                 Log.e("GPS", "provider enabled " + arg0);
> >         }
> >         public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
> >                 Log.e("GPS", "status changed to " + arg0 + " [" + arg1 + 
> > "]");
> >         }
>
> > }
>
> > and finally, main.xml:
>
> > <?xml version="1.0" encoding="utf-8"?>
> > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> > android"
> >     android:orientation="vertical"
> >     android:layout_width="fill_parent"
> >     android:layout_height="fill_parent"
> >     >
> >         <TextView
> >                 android:id="@+id/label1"
> >             android:layout_width="fill_parent"
> >             android:layout_height="fill_parent"
> >             android:text="@string/hello"
> >             />
> > </LinearLayout>
>
> > On Jan 26, 5:16 pm, "Justin (Google Employee)" <[email protected]>
> > wrote:
>
> > > Have you declared the appropriate permissions? Code would be useful
> > > here.
>
> > > Cheers,
> > > Justin
> > > Android Team @ Google
>
> > > On Jan 26, 1:33 pm, octagon <[email protected]> wrote:
>
> > > > Hello,
>
> > > > Is there any androidexamplecode for theGPSlocation manager that
> > > > has been demonstrated to actually work with theG1? I have been able
> > > > to get the emulator to work with no issues, but theG1stays in
> > > > TEMPORARILY_UNAVAILABLE status forever.GPSis actually working okay
> > > > on the phone in the Maps application. I'm going through the android
> > > > source code tracking down exactly what Maps is doing, but it's kind of
> > > > slow going and it would be very helpful to be able to see aknown-good
> > > >GPSexample. Thanks!
>
> > > > Micha
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to