Hi, MapActivity will start and display a map with latitude and longitude (0,0), I cannot get the current position, because I get this error:
09-16 12: 06: 46.515: ERROR / MapActivity (464): could not get connection factory client
Apiki is correct, I also reinstalled eclipse + android sdk and regenerated another debug.keystore and its relative apikey, but nothing changed.
The source is this (note that I do not see println in logcat System.out.println ("* I'm here here" + current_lat));
package it.me.map; 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.location.LocationProvider; import android.os.Bundle; import android.widget.TextView; import it.man.app.R; public class Maps extends MapActivity { private TextView tvName; private TextView tvAddress; private TextView tvOpenTime; private MapController mc; private MapView mapView; private static double current_lat; private static double current_long; private static LocationListener mNetworkListener = new LocationListener() { @Override public void onLocationChanged(Location location) { makeUseOfNewLocation(location); } @Override public void onProviderDisabled(String provider) {} @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) {} public void makeUseOfNewLocation(Location location) { current_lat = location.getLatitude(); current_long = location.getLongitude(); System.out.println("*** i'm here"+current_lat); } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.maps); mapView = (MapView) findViewById(R.id.mapview); mc = mapView.getController(); LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mNetworkListener); GeoPoint p = new GeoPoint((int)current_lat*(1000000), (int)current_long*(1000000)); mc.animateTo(p); } @Override protected boolean isRouteDisplayed() { return false; } }
maps.xml is:
<?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 xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:enabled="true" android:apiKey="02pmISdykDhJpseMz_d3XLv5ojPsNW25Tz9dtdA" /> </RelativeLayout>
and finally AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ir.marco.furesta" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <uses-library android:name="com.google.android.maps" /> <activity android:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Maps"></activity> <activity android:name=".NewsList"></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_COARSE_LOCATION" /> </manifest>
source share