Background:
App Overview: I'm developing an Android App that will display a list of places in a listview and then ultimately allows the user to display those places on a Google Map (using Google Map v2 API) when the user clicks on a button on the listview screen. At this point in time I'm just trying to display the list of places in the list view and simply display a map of my current location with a marker showing my location.
Current status: So far the app correctly displays the listview with the places but when the button is clicked to display the map all I get a blank screen with Zoom controls displayed. Below you will find the LogCat. I believe the key error message is as follows:
04-03 09:52:24.295: E/Google Maps Android API(1896): Failed to load map. Could not contact Google servers.
Platform: I'm developing the App to run on Froyo and later..but for now I'm just trying to get this to run on Froyo.
Keys: I have created a key with the following services enabled: "Google Maps Android API v2" and "Places API" turned on.
Here is the full LogCat. Note: the LogCat ends with and endless number of the "Could not contact Google servers" so I cut it off with the last 3 of these messages.
04-03 09:42:17.447: D/Your Location(1896): latitude:32.91296010000001, longitude: -117.17031355
04-03 09:42:36.577: D/dalvikvm(1896): threadid=1: still suspended after undo (sc=1 dc=1 s=Y)
04-03 09:42:36.577: D/dalvikvm(1896): GC_FOR_MALLOC freed 6014 objects / 359192 bytes in 82ms
04-03 09:42:39.467: D/Places Status(1896): OK
04-03 09:43:53.437: D/dalvikvm(1896): GC_FOR_MALLOC freed 7413 objects / 369560 bytes in 226ms
04-03 09:43:54.537: D/dalvikvm(1896): DexOpt: couldn't find field Landroid/content/res/Configuration;.smallestScreenWidthDp
04-03 09:43:54.537: W/dalvikvm(1896): VFY: unable to resolve instance field 23
04-03 09:43:54.537: D/dalvikvm(1896): VFY: replacing opcode 0x52 at 0x0012
04-03 09:43:54.537: D/dalvikvm(1896): VFY: dead code 0x0014-0018 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b (Landroid/content/res/Resources;)Z
04-03 09:43:56.117: D/dalvikvm(1896): GC_FOR_MALLOC freed 3000 objects / 314664 bytes in 84ms
04-03 09:43:56.307: W/dalvikvm(1896): Unable to resolve superclass of Lmaps/p/s; (425)
04-03 09:43:56.307: W/dalvikvm(1896): Link of class 'Lmaps/p/s;' failed
04-03 09:43:56.307: W/dalvikvm(1896): Unable to resolve superclass of Lmaps/y/bo; (3818)
04-03 09:43:56.307: W/dalvikvm(1896): Link of class 'Lmaps/y/bo;' failed
04-03 09:43:56.307: W/dalvikvm(1896): Unable to resolve superclass of Lmaps/i/k; (4206)
04-03 09:43:56.307: W/dalvikvm(1896): Link of class 'Lmaps/i/k;' failed
04-03 09:43:56.317: E/dalvikvm(1896): Could not find class 'maps.i.k', referenced from method maps.z.ag.a
04-03 09:43:56.317: W/dalvikvm(1896): VFY: unable to resolve new-instance 3538 (Lmaps/i/k;) in Lmaps/z/ag;
04-03 09:43:56.317: D/dalvikvm(1896): VFY: replacing opcode 0x22 at 0x006d
04-03 09:43:56.397: D/dalvikvm(1896): VFY: dead code 0x006f-007f in Lmaps/z/ag;.a (Landroid/view/LayoutInflater;Lcom/google/android/gms/maps/GoogleMapOptions;ZLjava/lang/String;)Lmaps/z/ag;
04-03 09:43:57.727: D/dalvikvm(1896): GC_FOR_MALLOC freed 4941 objects / 398416 bytes in 102ms
04-03 09:43:58.367: E/Google Maps Android API(1896): Failed to load map. Could not contact Google servers.
04-03 09:51:41.015: D/dalvikvm(1896): GC_FOR_MALLOC freed 5101 objects / 340064 bytes in 97ms
04-03 09:52:24.295: E/Google Maps Android API(1896): Failed to load map. Could not contact Google servers.
04-03 09:53:33.888: D/dalvikvm(1896): GC_EXTERNAL_ALLOC freed 1948 objects / 134008 bytes in 260ms
04-03 09:57:34.449: E/Google Maps Android API(1896): Failed to load map. Could not contact Google servers.
04-03 09:57:34.649: D/libEGL(1896): loaded /system/lib/egl/libGLES_android.so
04-03 09:57:34.679: D/libEGL(1896): loaded /system/lib/egl/libEGL_adreno200.so
04-03 09:57:34.869: D/libEGL(1896): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
04-03 09:57:34.879: D/libEGL(1896): loaded /system/lib/egl/libGLESv2_adreno200.so
04-03 09:57:35.009: E/Google Maps Android API(1896): Failed to load map. Could not contact Google servers.
04-03 09:57:35.109: E/Google Maps Android API(1896): Failed to load map. Could not contact Google servers.
04-03 09:57:35.199: E/Google Maps Android API(1896): Failed to load map. Could not contact Google servers.
The code that is responsible for displaying the maps is as follows:
public class PlacesMapActivity extends FragmentActivity {
// Nearest places
PlacesList nearPlaces;
private SupportMapFragment mMapFragment;
LatLng latLng;
double latitude;
double longitude;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_places);
// Getting intent data
Intent i = getIntent();
// Users current geo location
String user_latitude = i.getStringExtra("user_latitude");
String user_longitude = i.getStringExtra("user_longitude");
latLng = new LatLng(Double.parseDouble(user_latitude), Double.parseDouble(user_longitude));
// Nearplaces list
nearPlaces = (PlacesList) i.getSerializableExtra("near_places");
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
// Try to obtain the map from the SupportMapFragment.
mMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
// Not found so make a new instance and add it to the transaction for swapping
if (mMapFragment == null) {
mMapFragment = SupportMapFragment.newInstance();
ft.add(R.id.map, mMapFragment);
}
ft.commit();
}
@Override
public void onAttachedToWindow() {
// Load the map here such that the fragment has a chance to completely load or else the GoogleMap value may be null
GoogleMap googleMap;
googleMap = (mMapFragment).getMap();
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.addMarker(new MarkerOptions()
.position(latLng)
.title("My Spot")
.snippet("This is my spot!")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
googleMap.getUiSettings().setCompassEnabled(true);
googleMap.getUiSettings().setZoomControlsEnabled(true);
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 10));
super.onAttachedToWindow();
}
@Override
public void onAttachFragment(Fragment fragment) {
// TODO Auto-generated method stub
super.onAttachFragment(fragment);
}
Based on debugger results it appears that the extra values passed in via the intent are all present and correct.
Here is the XML for the Map layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
Not sure why the map isn't being displayed. Thoughts?