0

I am making a android application with google map. I have the required API key then also I am getting the error "could not get connection factory client". My codes are as follows.

AndroidManifest.xml

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

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="17" />
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
     Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.locationmap.MapMain"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <uses-library android:name="com.google.android.maps" />
</application>
</manifest>

The lay out for the main activity file activity_map_main.xml is :

<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MapMain" >

<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:apiKey="AIzaSyAsvPAsTMobh0Unrg5F78CHHpKnvMGCQ-k"
/>
</RelativeLayout>

The class file is : HelloItemizedOverlay.java

package com.example.locationmap;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class HelloItemizedOverlay extends ItemizedOverlay<OverlayItem>
{
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;

 public HelloItemizedOverlay(Drawable defaultMarker, Context context)
 {
     super(boundCenterBottom(defaultMarker));
     mContext = context;
 }

 public void addOverlay(OverlayItem overlay)
 {
     mOverlays.add(overlay);
     populate();
 }
 @Override
 protected OverlayItem createItem(int i)
 {
     return mOverlays.get(i);
 }
 @Override
 public int size()
 {
     return mOverlays.size();
 }
 @Override
 protected boolean onTap(int index)
 {
     OverlayItem item = mOverlays.get(index);
     AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
     dialog.setTitle(item.getTitle());
     dialog.setMessage(item.getSnippet());
     dialog.show();
     return true;
 }
}

The last class is MapMain.java

package com.example.locationmap;

import java.util.List;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;


public class MapMain extends MapActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map_main);

    MapView mapView = (MapView) findViewById(R.id.mapview);
     mapView.setBuiltInZoomControls(true);

     List<Overlay> mapOverlays = mapView.getOverlays();
     Drawable drawable = this.getResources().getDrawable(R.drawable.lightning);
     HelloItemizedOverlay itemizedoverlay = new     HelloItemizedOverlay(drawable,this);
     GeoPoint point = new GeoPoint(30443769,-91158458);
     OverlayItem overlayitem = new OverlayItem(point, "Laissez les bon temps rouler!", "I'm in Louisiana!");

     GeoPoint point2 = new GeoPoint(17385812,78480667);
     OverlayItem overlayitem2 = new OverlayItem(point2, "Namashkaar!", "I'm in Hyderabad, India!");

     itemizedoverlay.addOverlay(overlayitem);
     itemizedoverlay.addOverlay(overlayitem2);

     mapOverlays.add(itemizedoverlay);
}

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.map_main, menu);
    return true;
}

}

Please help me relating to the error. Thanks,

4

0 回答 0