2012-08-10 91 views
0

在我的应用程序中,我使用谷歌地图功能。为此,我使用自己的密钥存储并创建了MD5指纹。后来我得到了基于该MD5的基于Google的xml。地图不是显示在Android设备

问题:

它是工作在emulator.But没有出现在现实device.But电网什么是可见的。

样本 - 类

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清单

<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_a[email protected]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 

任何人都可以找出为什么地图不显示在设备中。预先感谢

+0

重新生成API密钥,然后再试一次 – pixelscreen 2012-08-10 09:11:42

+0

我已经完成了很多次。但只有网格显示在设备中。 – 2012-08-10 09:12:45

+0

http://stackoverflow.com/q/2641197/735675试试这个。同样确切的问题。 – pixelscreen 2012-08-10 09:16:40

回答

0

实际上我发现的问题是,只有当应用程序从android市场下载时,Mapview才会显示,因为我们使用签名的api密钥。

我认为这就是为什么它在运行eclipse时没有显示。

+0

不,当然可以通过android模拟器显示MapView。为此,您必须从https://developers.google.com/android/maps-api-signup – 2012-08-16 08:29:05

+0

获取Google地图api密钥以用于模拟器,它将使用默认密钥库显示。但对于设备,我们应该手动创建密钥库,我想是这样。 – 2012-09-05 12:04:10

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

还请确保您的设备可以访问Internet。