地图未在Android设备中显示

时间:2012-08-10 09:07:49

标签: android google-maps

在我的应用程序中,我使用谷歌地图功能。因为我使用自己的密钥库并创建了MD5指纹。后来我从谷歌的MD5获得了我的xml。

问题:

它在模拟器中工作。但没有在真实设备中显示任何内容。但网格是可见的。

样本 - 类

public class First extends MapActivity {
private MapController mc;
private MapView mapView;

private static double current_lat;
private static double current_long;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
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);  

}
private static LocationListener mNetworkListener = new LocationListener() 
{
public void onLocationChanged(Location location) {
makeUseOfNewLocation(location);
}

    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    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
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

Android Manifest

<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"/>

<application
  android:icon="@drawable/ic_launcher"
  android:label="@string/app_name" >

   <activity
     android:name=".First"
     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>

主要

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

<com.google.android.maps.MapView
 android:id="@+id/mapview"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:apiKey="0wINx0c2YuEd3mkyPwidZyeoz_HiyN3jrts-Q" />

</LinearLayout>

logcat的

 08-10 14:27:56.841: W/MapActivity(20815): Recycling dispatcher       android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher@405b  9458
 08-10 14:27:56.851: V/MapActivity(20815): Recycling map object.
 08-10 14:27:56.901: I/MapActivity(20815): Handling network change   notification:CONNECTED
 08-10 14:27:56.901: E/MapActivity(20815): Couldn't get connection factory client

任何人都可以找出为什么地图没有在设备中显示。提前谢谢

2 个答案:

答案 0 :(得分:0)

用此替换mapview xml代码,然后重试。

<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="Your API Key"
/>

还要确保您的设备可以访问互联网。

答案 1 :(得分:0)

实际上我想到的问题是Mapview只会显示应用程序是从Android市场下载的,因为我们使用的是签名的api密钥。

我认为这就是为什么,它在通过eclipse运行时没有显示出来。