GPS in SDK1.0

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

GPS in SDK1.0

Postby cassianotartari » Sun Nov 16, 2008 8:05 pm

Hi,

I'm trying to emulate GPS function but something is wrong, and I don't have idea what it is, I tried everything.

In attach a kml file to test the gps and the LogCat.

Note that in the last line when I load the kml the LogCat show:
Code: Select all
===>>> MyLocationListener onStatusChanged STATUS:2 PROVIDER:gps



Map.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package br.cassianotartari;
  2.  
  3. import com.google.android.maps.GeoPoint;
  4. import com.google.android.maps.MapActivity;
  5. import com.google.android.maps.MapController;
  6. import com.google.android.maps.MapView;
  7.  
  8. import android.content.Context;
  9. import android.location.Location;
  10. import android.location.LocationListener;
  11. import android.location.LocationManager;
  12. import android.os.Bundle;
  13. import android.util.Log;
  14. import android.widget.Toast;
  15.  
  16. public class Map extends MapActivity {
  17.  
  18.         private LocationManager lm;
  19.         private LocationListener locationListener;
  20.  
  21.         private MapView mapView;
  22.         private MapController mc;
  23.  
  24.         private static final String TAG = "Map Test";
  25.  
  26.     /** Called when the activity is first created. */
  27.     @Override
  28.     public void onCreate(Bundle savedInstanceState) {
  29.         super.onCreate(savedInstanceState);
  30.         setContentView(R.layout.main);
  31.  
  32.         lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  33.  
  34.         locationListener = new MyLocationListener();
  35.  
  36.         lm.requestLocationUpdates(
  37.                         LocationManager.GPS_PROVIDER,
  38.                         0,
  39.                         0,
  40.                         locationListener);
  41.  
  42.         mapView = (MapView) findViewById(R.id.map);
  43.         mc = mapView.getController();
  44.     }
  45.  
  46.         @Override
  47.         protected boolean isRouteDisplayed() {
  48.                 // TODO Auto-generated method stub
  49.                 return false;
  50.         }
  51.  
  52.         private class MyLocationListener implements LocationListener {
  53.                 public void onLocationChanged(Location loc) {
  54.                         //Called when the location has changed.
  55.                         Log.d(TAG, "===>>> MinhaLocalizacaoListener onLocationChanged");
  56.                         if (loc != null) {
  57.                 Toast.makeText(getBaseContext(),
  58.                     "Location changed : Lat: " + loc.getLatitude() +
  59.                     " Lng: " + loc.getLongitude(),
  60.                     Toast.LENGTH_SHORT).show();
  61.  
  62.                 GeoPoint p = new GeoPoint(
  63.                         (int) (loc.getLatitude() * 1E6),
  64.                         (int) (loc.getLongitude() * 1E6));
  65.                 mc.animateTo(p);
  66.                 mc.setZoom(16);
  67.                 mapView.invalidate();
  68.             }
  69.                 }
  70.                 public void onProviderDisabled(String provider) {
  71.                         //Called when the provider is disabled by the user.
  72.                         Log.d(TAG, "===>>> MyLocationListener onProviderDisabled PROVIDER:"+provider);
  73.                         //Mapa.ehPraAtualizar = false;
  74.                 }
  75.                 public void onProviderEnabled(String provider) {
  76.                         Log.d(TAG, "===>>> MyLocationListener onProviderEnabled PROVIDER:"+provider);
  77.                         //Called when the provider is enabled by the user.
  78.                 }
  79.                 public void onStatusChanged(String provider, int status, Bundle extras) {
  80.                         Log.d(TAG, "===>>> MyLocationListener onStatusChanged STATUS:"+status+" PROVIDER:"+provider);
  81.                         //Called when the provider status changes.
  82.                 }
  83.         }
  84. }
Parsed in 0.041 seconds, using GeSHi 1.0.8.4


main.xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.        android:layout_width="fill_parent"
  4.        android:layout_height="fill_parent">
  5.         <com.google.android.maps.MapView android:id="@+id/map"
  6.                android:layout_width="fill_parent"
  7.                android:layout_height="fill_parent"
  8.                android:apiKey="MY_OWN_APIKEY"
  9.                android:clickable="true" />
  10. </RelativeLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


AndroidManifest.xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.      package="br.cassianotartari"
  4.      android:versionCode="1"
  5.      android:versionName="1.0.0">
  6.  
  7.         <!-- Permissions -->
  8.     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  9.     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  10.     <uses-permission android:name="android.permission.INTERNET" />
  11.  
  12.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  13.  
  14.         <!-- Libraries -->
  15.         <uses-library android:name="com.google.android.maps" />
  16.  
  17.         <!-- Activities -->
  18.         <activity android:name=".Map"
  19.                  android:label="@string/app_name">
  20.             <intent-filter>
  21.                 <action android:name="android.intent.action.MAIN" />
  22.                 <category android:name="android.intent.category.LAUNCHER" />
  23.             </intent-filter>
  24.         </activity>
  25.  
  26.     </application>
  27. </manifest>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4
Attachments
eclipse.png
Adding kml file
eclipse.png (46.43 KiB) Viewed 366 times
house_defense_earmarks_08.kml.zip
KML file
(89.97 KiB) Downloaded 53 times
device.png
Emulator
device.png (37.29 KiB) Viewed 366 times
log.txt
LogCat
(31.83 KiB) Downloaded 69 times
public class pessoa {
private String nome = "Cassiano Tartari";
private String url = "www.cassianotartari.eng.br"
}
User avatar
cassianotartari
Developer
Developer
 
Posts: 28
Joined: Thu Aug 28, 2008 3:42 pm

Top

Postby Aldjinn » Mon Nov 17, 2008 4:56 pm

Hi cassianotartari,
your code seams to be OK. Maybe the problem isn't your code. I'm using a German Windows XP and had to set my regional settings to US the get the GPS function from the emulator to work. The problem is the notation of numbers, for example 50.00 (US) vs. 50,00 (Germany).

Aldjinn
Aldjinn
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Nov 11, 2008 9:09 am

Postby cassianotartari » Tue Nov 18, 2008 12:46 am

Aldjinn wrote:Hi cassianotartari,
your code seams to be OK. Maybe the problem isn't your code. I'm using a German Windows XP and had to set my regional settings to US the get the GPS function from the emulator to work. The problem is the notation of numbers, for example 50.00 (US) vs. 50,00 (Germany).

Aldjinn


THANKS A LOT !

WORKs fine !

I'm using Kubuntu 8.04, but the /etc/default/locale was like this:
Code: Select all
LANG="pt_BR.UTF-8"
LANGUAGE="pt_BR:pt:en"


And now is:
Code: Select all
LANG=en_US.ISO-8859-1
LANGUAGE=en_US:en
LC_CTYPE=en_US.utf8
LC_NUMERIC=en_US.utf8
LC_TIME=pt_BR
LC_COLLATE=en_US.utf8
LC_MONETARY=pt_BR
LC_MESSAGES=en_US.utf8
LC_PAPER=pt_BR
LC_NAME=pt_BR
LC_ADDRESS=en_US.utf8
LC_TELEPHONE=pt_BR
LC_MEASUREMENT=pt_BR
LC_IDENTIFICATION=en_US.utf8
LC_ALL=
public class pessoa {
private String nome = "Cassiano Tartari";
private String url = "www.cassianotartari.eng.br"
}
User avatar
cassianotartari
Developer
Developer
 
Posts: 28
Joined: Thu Aug 28, 2008 3:42 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 2 guests