Reputation: 255
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
Upvotes: 1
Views: 1253
Reputation: 26
I got same problem
You dont have to extend MapActivity while getting gps signal
use Activity then, foward to MapActivity
dont know reason though :(
Upvotes: 1
Reputation: 5203
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
Upvotes: 1