2011-10-31 50 views
0

關於應用程序: - 這是一個簡單的應用程序,它可以找到用戶當前的位置。Android地圖查看手機和模擬器不同

問題: - 該應用程序在仿真器上正常工作,請參閱圖像。

enter image description here

但在手機它沒有顯示在MapView.Please看到圖像。

enter image description here

請告訴我什麼是與手機腳麻。在手機中,只需下載巨大(20 MB)的數據,但不顯示實際的地圖。

logcat的即時得到 -

10-31 16:44:45.994: E/MapActivity(3026): Couldn't get connection factory client 

    10-31 15:47:42.319: ERROR/MapView(1773): java.lang.IllegalStateException: Null Bitmap! "loading_tile"; if seen during a test, this usually means that the image file needs to be added to the test.config file 

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

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

<com.google.android.maps.MapView 
android:id="@+id/myMapView" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent" 
android:clickable="true" 
android:enabled="true" 
android:apiKey="0bBgLl42nWwnTf983Y5VdIgfZI6mC7meL7Ms_qg"/> 

</LinearLayout> 

代碼

public class WhereIam extends MapActivity { 
MapController mapController; 
MyPositionOverlay positionOverlay; 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    MapView myMapView=(MapView)findViewById(R.id.myMapView); 
    mapController=myMapView.getController(); 
    myMapView.setSatellite(true); 
    myMapView.setStreetView(true); 
    myMapView.displayZoomControls(false); 
    myMapView.setBuiltInZoomControls(true); 
    mapController.setZoom(16); 
    positionOverlay = new MyPositionOverlay(); 
    List<Overlay> overlays = myMapView.getOverlays(); 
    overlays.add(positionOverlay); 
    LocationManager locationManager; 
    String context=Context.LOCATION_SERVICE; 
    locationManager=(LocationManager)getSystemService(context); 

    Criteria criteria = new Criteria(); 
    criteria.setAccuracy(Criteria.ACCURACY_FINE); 
    criteria.setAltitudeRequired(false); 
    criteria.setBearingRequired(false); 
    criteria.setCostAllowed(true); 
    criteria.setPowerRequirement(Criteria.POWER_LOW); 
    String provider = locationManager.getBestProvider(criteria, true); 
    Location location = locationManager.getLastKnownLocation(provider); 

    final LocationListener locationListener = new LocationListener() { 
     public void onLocationChanged(Location location) { 
     updateWithNewLocation(location); 
     } 
     public void onProviderDisabled(String provider){ 
     updateWithNewLocation(null); 
     } 
     public void onProviderEnabled(String provider){ } 
     public void onStatusChanged(String provider, int status, 
     Bundle extras){ } 
     }; 

    updateWithNewLocation(location); 
    locationManager.requestLocationUpdates(provider, 2000, 10, 
      locationListener); 
} 

private void updateWithNewLocation(Location location) { 
    String latLongString; 
    TextView myLocationText; 
    String addressString ="No Address Found"; 
    myLocationText=(TextView)findViewById(R.id.myLocationText); 
    if(location!=null) { 
     // Update the map location. 
     positionOverlay.setLocation(location); 
     Double geoLat = location.getLatitude()*1E6; 
     Double geoLng = location.getLongitude()*1E6; 
     GeoPoint point = new GeoPoint(geoLat.intValue(), 
     geoLng.intValue()); 
     mapController.animateTo(point); 
     double lat=location.getLatitude(); 
     double lng=location.getLongitude(); 
     latLongString = "Lat:" + lat + "\nLong:" + lng; 
     Geocoder gc=new Geocoder(this, Locale.getDefault()); 
     try { 
      List<Address> addressess= gc.getFromLocation(lat, lng, 1); 
      StringBuilder sb=new StringBuilder(); 
      if(addressess.size()>0) { 
       Address address=addressess.get(0); 
       for(int i=0;i<address.getMaxAddressLineIndex();i++) { 
        sb.append(address.getAddressLine(i)).append("\n"); 
        sb.append(address.getLocality()).append("\n"); 
        sb.append(address.getPostalCode()).append("\n"); 
        sb.append(address.getCountryName()); 
       } 
       addressString = sb.toString(); 
      } 
     }catch(IOException e) {} 
    } 
    else { 
     latLongString="No Found Location"; 
    } 
    myLocationText.setText("Your current Location is \n"+latLongString+"\n"+addressString); 
} 

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

}

我只是一個裝箱API密鑰如下goto->命令提示符

變化的目錄密鑰工具夾

現在運行命令密鑰工具-list -alias androiddebugkey -keystore 「C:\用戶\ pc.android \ debug.keystore」 -storepass機器人-keypass機器人

看到圖像enter image description here

現在我轉到註冊頁面我只是把EditText上的MD5和檢查接受並點擊生成密鑰,然後下面的頁面出現這顯示key--

enter image description here 現在我把這個密鑰放在我的MapView Xml文件中。

你可以看到應用在模擬器中運行正常,但在真實手機中沒有。

我在哪裏出錯,以及如何爲真實手機生成第二個API密鑰?

+2

手機中的應用程序是通過android市場下載的?或者它是您使用的調試.apk?你知道你必須用有效的密鑰簽署你的地圖,而不是調試密鑰嗎? – Ivan

+0

是的,我用有效的api密鑰簽署我的應用程序 – Sunny

+0

該應用程序在市場上?如果答案是肯定的,那麼API密鑰必須與用於簽署應用程序的密鑰相同。 – Ivan

回答

3

要在真實硬件上測試,您需要使用與調試密鑰不同的密鑰。在您的文章之後,您正在使用調試密鑰庫。

https://developers.google.com/maps/documentation/android-api/v1/?csw=1#getfingerprint

閱讀谷歌的那款。

將應用程序導出爲具有與用於Google API(而不是調試密鑰)相同的密鑰的簽名應用程序很重要。

對於創建一個有效的閱讀段落:

http://developer.android.com/guide/publishing/app-signing.html#releasemode

,然後使用相同的密鑰來獲得谷歌地圖API密鑰。

一旦你有了你的應用程序的鑰匙,你可以導出一個簽名的應用程序,通過點擊鼠標右鍵在項目上選擇Android工具,然後導出爲一個已簽名的應用程序包,並按照嚮導(可能你可以創建一個使用該向導的新密鑰)。

希望有所幫助。

0

我不知道它是否是"this question"的相同錯誤,因爲當瓷磚加載時(或者當API密鑰錯誤時它們從未完成加載)它顯示灰色網格的白色背景。

反正你得到日誌相同的錯誤,所以讓我們去那個方向:

正如我在這個問題自我回答,您必須有2個API密鑰:一個用於調試使用的仿真器,以及另一個用於真實設備。最後一個必須手動創建。它可以通過命令提示符或Eclipse選項完成。

一旦您創建了API密鑰dor real設備,您必須創建APK並右鍵單擊該項目並導出爲已簽名的apk。

一切都很好地解釋了here,而且這個問題也已在此處提出,其解決方案在Eclipse in accepted answer for this question中有很好的描述。

+0

Rdge感謝您的回覆我已添加了一個答案,告訴我遵循的程序請進行審查。 – Sunny