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
Using java Syntax Highlighting
- package br.cassianotartari;
- import com.google.android.maps.GeoPoint;
- import com.google.android.maps.MapActivity;
- import com.google.android.maps.MapController;
- import com.google.android.maps.MapView;
- import android.content.Context;
- import android.location.Location;
- import android.location.LocationListener;
- import android.location.LocationManager;
- import android.os.Bundle;
- import android.util.Log;
- import android.widget.Toast;
- public class Map extends MapActivity {
- private LocationManager lm;
- private LocationListener locationListener;
- private MapView mapView;
- private MapController mc;
- private static final String TAG = "Map Test";
- /** 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);
- locationListener = new MyLocationListener();
- lm.requestLocationUpdates(
- LocationManager.GPS_PROVIDER,
- 0,
- 0,
- locationListener);
- mapView = (MapView) findViewById(R.id.map);
- mc = mapView.getController();
- }
- @Override
- protected boolean isRouteDisplayed() {
- // TODO Auto-generated method stub
- return false;
- }
- private class MyLocationListener implements LocationListener {
- public void onLocationChanged(Location loc) {
- //Called when the location has changed.
- Log.d(TAG, "===>>> MinhaLocalizacaoListener onLocationChanged");
- if (loc != null) {
- Toast.makeText(getBaseContext(),
- "Location changed : Lat: " + loc.getLatitude() +
- " Lng: " + loc.getLongitude(),
- Toast.LENGTH_SHORT).show();
- GeoPoint p = new GeoPoint(
- (int) (loc.getLatitude() * 1E6),
- (int) (loc.getLongitude() * 1E6));
- mc.animateTo(p);
- mc.setZoom(16);
- mapView.invalidate();
- }
- }
- public void onProviderDisabled(String provider) {
- //Called when the provider is disabled by the user.
- Log.d(TAG, "===>>> MyLocationListener onProviderDisabled PROVIDER:"+provider);
- //Mapa.ehPraAtualizar = false;
- }
- public void onProviderEnabled(String provider) {
- Log.d(TAG, "===>>> MyLocationListener onProviderEnabled PROVIDER:"+provider);
- //Called when the provider is enabled by the user.
- }
- public void onStatusChanged(String provider, int status, Bundle extras) {
- Log.d(TAG, "===>>> MyLocationListener onStatusChanged STATUS:"+status+" PROVIDER:"+provider);
- //Called when the provider status changes.
- }
- }
- }
Parsed in 0.016 seconds, using GeSHi 1.0.8.4
main.xml
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <com.google.android.maps.MapView android:id="@+id/map"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:apiKey="MY_OWN_APIKEY"
- android:clickable="true" />
- </RelativeLayout>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
AndroidManifest.xml
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="br.cassianotartari"
- android:versionCode="1"
- android:versionName="1.0.0">
- <!-- Permissions -->
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
- <uses-permission android:name="android.permission.INTERNET" />
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <!-- Libraries -->
- <uses-library android:name="com.google.android.maps" />
- <!-- Activities -->
- <activity android:name=".Map"
- 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>
- </manifest>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4