2011-10-31 45 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