无法找到提供商信息com.google.settings Android Map

时间:2013-01-21 07:04:04

标签: android

我的Android应用程序使用MapView,但在使用MapView启动活动后,我连续得到了三个错误:

无法找到提供商信息com.google.settings

以后

无法获得连接工厂客户端

我已设置所有权限和Api密钥。但是会显示网格地图。

我在过去2周内解决了这个问题,但我没有解决..

有人知道如何解决这个问题吗?

这是我的代码

public class AndroidGPSApplicationActivity extends MapActivity {

    private MapView map=null;
    private MyLocationOverlay me=null;
    private ToggleButton toggle_button;
    private TextView latitude=null;
    public double value;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        map=(MapView)findViewById(R.id.mapview);
        map.getController().setCenter(getPoint(34.0043,71.5448));
        map.getController().setZoom(13);
        map.setBuiltInZoomControls(true);
        map.setTraffic(true);

        Drawable marker=getResources().getDrawable(R.drawable.marker);

        marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight());

        map.getOverlays().add(new SitesOverlay(marker));

        me=new MyLocationOverlay(this, map);
        map.getOverlays().add(me);

        MapOverlay mapOverlay = new MapOverlay();
        List<Overlay> listOfOverlays = map.getOverlays();
        listOfOverlays.add(mapOverlay);

        tabView();

        latitude = (TextView)findViewById(R.id.latitude_value);
        //latitude.setText(null);

        toggle_button = (ToggleButton)findViewById(R.id.togglebutton);
        toggle_button.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if(toggle_button.isChecked())
              {
                enableGps();
                Toast.makeText(getApplicationContext(), "The state of GPS is changed to on", Toast.LENGTH_LONG).show();
              }
            else
              {
                disableGps();
                Toast.makeText(getApplicationContext(), "The state of GPS is changed to off", Toast.LENGTH_LONG).show();
              }

            }
        });

    }       // end of onCreate(); function

    @Override
    public void onResume() {
        super.onResume();
        me.enableCompass();
    }       

    @Override
    public void onPause() {
        super.onPause();
        me.disableCompass();
    }   
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_S) {
            map.setSatellite(!map.isSatellite());
            return(true);
        }
        else if (keyCode == KeyEvent.KEYCODE_Z) {
            map.displayZoomControls(true);
            return(true);
        }

        return(super.onKeyDown(keyCode, event));
    }
    private void tabView() {                                //setting two tabs ..for Map and Update

        TabHost tabs = (TabHost)findViewById(R.id.TabHost01);
        tabs.setup();
        TabHost.TabSpec spec1 = tabs.newTabSpec("tag1");
        spec1.setContent(R.id.setting);
        spec1.setIndicator("Setting");

        tabs.addTab(spec1);

        //TabHost tabs = (TabHost)findViewById(R.id.TabHost01);
        //tabs.setup();
        TabHost.TabSpec spec2 = tabs.newTabSpec("tag2");
        spec2.setContent(R.id.layout1);
        spec2.setIndicator("Map");

        tabs.addTab(spec2);

        TabHost.TabSpec spec3 = tabs.newTabSpec("tag3");
        spec3.setContent(R.id.layout2);   
        spec3.setIndicator("Stastistics");

        tabs.addTab(spec3);

    }

    protected void disableGps() {   
        Intent intent=new Intent("android.location.GPS_ENABLED_CHANGE"); 
        intent.putExtra("enabled", false); 
        sendBroadcast(intent); 
    }

    protected void enableGps() 
    {
        Intent intent=new Intent("android.location.GPS_ENABLED_CHANGE"); 
        intent.putExtra("enabled", true); 
        sendBroadcast(intent); 
    }

    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

    private GeoPoint getPoint(double lat, double lon) {
        return(new GeoPoint((int)(lat*1000000.0), (int)(lon*1000000.0)));
    }
    /*
     * This is an inner class .
     * for puting an image on specified location..
     */
    private class SitesOverlay extends ItemizedOverlay<OverlayItem> {
        private List<OverlayItem> items=new ArrayList<OverlayItem>();
        private Drawable marker=null;

        public SitesOverlay(Drawable marker) {
            super(marker);
            this.marker=marker;

            items.add(new OverlayItem(getPoint(34.0043, 71.5448),"PK", "PTCL Office Cantt"));
            items.add(new OverlayItem(getPoint(34.004124555, 71.4859698), "Lincoln Center", "Department of Computer Science"));
            items.add(new OverlayItem(getPoint(34.03484758, 71.54653569), "Carnegie Hall", "Where you go with practice, practice, practice"));
            items.add(new OverlayItem(getPoint(34.07492254, 71.5464754), "The Downtown Club", "Original home of the Heisman Trophy"));

            populate();
        }

        @Override
        protected OverlayItem createItem(int i) {
            return(items.get(i));
        }

        @Override
        public void draw(Canvas canvas, MapView mapView, boolean shadow) {
            super.draw(canvas, mapView, shadow);    
            boundCenterBottom(marker);
        }

        @Override
        protected boolean onTap(int i) {
            Toast.makeText(AndroidGPSApplicationActivity.this, items.get(i).getSnippet(),
                            Toast.LENGTH_SHORT).show(); 
            return(true);
        }

        @Override
        public int size() {
            return(items.size());
        }
    }

     private class MapOverlay extends Overlay
        {
            @Override
            public boolean onTouchEvent(MotionEvent event, MapView mapView)
            {

                //---when user lifts his finger---
                if (event.getAction() == 1) {
                    GeoPoint p = mapView.getProjection().fromPixels(
                        (int) event.getX(),
                        (int) event.getY());
                        Toast.makeText(getBaseContext(),
                            "Location: "+
                            p.getLatitudeE6() / 1E6 + "," +
                            p.getLongitudeE6() /1E6 ,
                            Toast.LENGTH_SHORT).show();
                        value= p.getLatitudeE6() / 1E6 ;                     
                        String str_value = Double.toString(value);
                        latitude.setText(str_value);
                }
                return false;
            }
        }
}

Xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

    <TabHost
      android:id="@+id/TabHost01" 
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">
    <TabWidget 
      android:id="@android:id/tabs"
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" />
    <FrameLayout 
      android:id="@android:id/tabcontent"
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingTop="90dp"     
        >
        <TextView 
          android:id="@+id/setting" 
          android:text="@string/setting_tab" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" />

        <RelativeLayout
            android:id="@+id/layout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            >
    <com.google.android.maps.MapView
                android:id="@+id/mapview"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:apiKey="Api Key"
                 android:clickable="true"
                 />
   <ToggleButton 
                android:id="@+id/togglebutton"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:textOn="ON"
                android:textOff="OFF"
                android:layout_alignParentBottom="true"/>


    </RelativeLayout>

      <LinearLayout
            android:id="@+id/layout2"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            >
      <TextView 
          android:id="@+id/latitude_lbl" 
          android:text="@string/latitude" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" /> 

      <TextView 
          android:id="@+id/latitude_value" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" />

      <TextView 
          android:id="@+id/longitude_lbl" 
          android:text="@string/longitude" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" /> 

          </LinearLayout>   

    </FrameLayout>
  </TabHost>
</LinearLayout>

清单文件

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

    <uses-sdk android:minSdkVersion="4" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
         <uses-library android:name="com.google.android.maps"/>
        <activity
            android:name=".AndroidGPSApplicationActivity"
            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>
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
     <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission>
</manifest>

1 个答案:

答案 0 :(得分:0)

检查您是否在清单中设置了以下行

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