Darko Petkovski
Darko Petkovski

Reputation: 3912

Android google map shows blank

I'm trying to implement google maps V2 but the maps is showing blank. I've edited the manifest, created xml layout and the activity but maps is showing blank.

Here is what i did to the manifest:

<permission
        android:name="com.biznismap.com.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.biznismap.com.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

and added this in as the first child of application node in the manifest:

<uses-library android:name="com.google.android.maps" />

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="my_key" />

Here is my map xml layout:

<?xml version="1.0" encoding="utf-8"?>
<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:apiKey="my_key"
    android:clickable="true" />

Here is my MapActivity:

public class ListingMap extends MapActivity {

    private HelloItemizedOverlay itemizedoverlay;
    private List<Overlay> mapOverlays;
    private String lat, lng;

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

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

        mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(
                R.drawable.ic_launcher);
        itemizedoverlay = new HelloItemizedOverlay(drawable);
        getExtras();
    }

    private void getExtras() {
        Bundle extras = getIntent().getExtras();
        lat = extras.getString("lat");
        lng = extras.getString("lng");
        Log.v("--", lat+" "+lng);
        float latitude=Float.valueOf(lat);
        float longitude=Float.valueOf(lng);
        GeoPoint point = new GeoPoint((int)(latitude * 1E6),(int)(longitude * 1E6));
        OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!",
                "I'm in Mexico City!");
        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);
    }

}

So everything is going OK but, when I want to display something, the map is blank, and I get this from the emulator:

06-02 17:09:26.921: E/MapActivity(1772): Couldn't get connection factory client

So where am I going wrong, and how can I fix this problem?

Upvotes: 1

Views: 2395

Answers (4)

Alex
Alex

Reputation: 1192

Here is what https://developers.google.com/maps/documentation/android/v1/hello-mapview says:

Note: Version 1 of the Google Maps Android API has been officially deprecated as of December 3rd, 2012. This means that from March 18th, 2013 you will no longer be able to request an API key for this version. No new features will be added to Google Maps Android API v1. However, apps using v1 will continue to work on devices. Existing and new developers are encouraged to use Google Maps Android API v2.

Your code is miximg v1 and v2 properties.

Upvotes: 0

Divya Motiwala
Divya Motiwala

Reputation: 1669

MapView is no more used with API v2. Instead use :

   <fragment
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.google.android.gms.maps.SupportMapFragment"/>

Accordingly, use FragmentActivity instead of MapActivity and inflate the map.

You can check Loading Map using Google Map API V2 for more details

Upvotes: 0

webo80
webo80

Reputation: 3403

You have two problems here. In v2 you may not use

<uses-library android:name="com.google.android.maps" />

, and your layout is invalid. If you want full-layout map, just use this:

<FrameLayout
... >

    <fragment
        ...
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />
</FrameLayout>

On your Java code, use FragmentActivity and:

    map = ((SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.your_id)).getMap();

This way, you will get compatibity with pre-honeycomb devices. Good luck!

Upvotes: 1

Booger
Booger

Reputation: 18725

Either you don't have internet connectivity (my guess), or the key you entered in incorrect. Double check both these things.

Also, ensure the emulator you are using to test (if applicable) has the Google APIs installed.

Upvotes: 0

Related Questions