1

i'm testing an app of getting current location with sumsung galaxy spica, it show me another location different from my one and it isn't the same showed in the AVD!! gps is activated but i don't know where is the problem exactly. Here is my code

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.Toast;

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 com.google.android.maps.MyLocationOverlay;

public class MaptestActivity extends MapActivity implements LocationListener {
    private MapView mapView = null;
    private LocationManager lm = null;
    private double lat = 0;
    private double lng = 0;
    private MapController mc = null;
    private MyLocationOverlay myLocation = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mapView = (MapView) this.findViewById(R.id.mapView);
    mapView.setBuiltInZoomControls(true);

    lm = (LocationManager) this.getSystemService(LOCATION_SERVICE);
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0, this);
    lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 0, this);




    myLocation = new MyLocationOverlay(getApplicationContext(), mapView);
    myLocation.runOnFirstFix(new Runnable() {
        public void run() {
        mc.animateTo(myLocation.getMyLocation());
        mc.setZoom(17);
        mc = mapView.getController();
        lat = myLocation.getMyLocation().getLatitudeE6();
        lng = myLocation.getMyLocation().getLongitudeE6();
        Toast.makeText(
                getBaseContext(),
                "My Location : Latitude = " + lat + " Longitude = "
                    + lng, Toast.LENGTH_LONG).show();
        }
    });
    mapView.getOverlays().add(myLocation);
    }

    @Override
    protected void onResume() {
    super.onResume();
    myLocation.enableMyLocation();
    myLocation.enableCompass();
    }

    @Override
    protected boolean isRouteDisplayed() {
    return false;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_S) {
        mapView.setSatellite(!mapView.isSatellite());
        return true;
    }
    return super.onKeyDown(keyCode, event);
    }

    public void onLocationChanged(Location location) {
    lat = location.getLatitude();
    lng = location.getLongitude();
    Toast.makeText(
        getBaseContext(),
        "Location change to : Latitude = " + lat + " Longitude = "
            + lng, Toast.LENGTH_SHORT).show();
    GeoPoint p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
    mc.animateTo(p);
    mc.setCenter(p);
    }


    public void onProviderDisabled(String provider) {
    }


    public void onProviderEnabled(String provider) {
    }


    public void onStatusChanged(String provider, int status, Bundle extras) {
    }

}

here is my manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.manita.maptest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="3" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <uses-library android:name="com.google.android.maps" />
        <activity
            android:name=".MaptestActivity"
            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.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_GPS" />
    <uses-permission android:name="android.permission.ACCESS_COARSE" />
    <uses-permission android:name="android.permission.LOCATION" />

</manifest>

and here the error in the logcat

01-10 10:37:47.765: E/Sensors(5222): ####### akmd2 started!!!
01-10 10:37:47.770: E/SensorManager(5222): registerListener 0:AK8973 Compass
01-10 10:37:47.950: E/SensorManager(5222): =======>>>>>>> Sensor Thread RUNNING <<<============================
01-10 10:37:47.995: I/MapActivity(5222): Handling network change notification:CONNECTED
01-10 10:37:47.995: E/MapActivity(5222): Couldn't get connection factory client

Thanks

manita marwa
  • 255
  • 1
  • 4
  • 13
  • What do you mean it's different from the AVD? It should obviously be different. – Reno Jan 10 '12 at 12:55
  • yes i know but if it's different that means it's the right one!! in my case in the AVD it show Tulsa! and in my phone it show me another place (bievre igny) in french and my current location i'm in tunisia now – manita marwa Jan 10 '12 at 13:17
  • Can you edit your question to include the lat, lon you get in `onLocationChanged()`. Also comment `lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 0, this);` – Reno Jan 10 '12 at 13:33
  • i did but the same :'(. see the code i'm making a toast in the runOnFirstFix () it doesn't appear this msg that means that the program doesn't run this function runOnFirstFix() may be the pbm is there?? – manita marwa Jan 10 '12 at 13:38
  • 1
    You have to go outside, you won't get a GPS signal in a building with `GPS_PROVIDER` – Reno Jan 10 '12 at 13:53
  • i didn't understand what u mean by getting gps signal in a building with gps_provider? – manita marwa Jan 10 '12 at 14:25

2 Answers2

1

Check out this link Couldn't get connection factory client

In Google Group : solution mention that you have to put proper API KEY for map

Community
  • 1
  • 1
rajpara
  • 5,203
  • 1
  • 29
  • 46
1

I got same problem

You dont have to extend MapActivity while getting gps signal

use Activity then, foward to MapActivity

dont know reason though :(

jji
  • 26
  • 1