Android的图形页面在手机和模拟器不同 [英] Android mapView different in phone and emulator

查看:101
本文介绍了Android的图形页面在手机和模拟器不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于应用程序: - 这是一个简单的应用程序,它发现用户当前位置

About App:--This is a simple app which find the user current location.

问题: - 这个应用程序正常工作的模拟器请参考图片

Problem:-- The app works fine on emulator please see the image.

但在手机它没有显示在MapView.Please看到的图像。

But in phone it is not showing the MapView.Please see the image.

请告诉我什么是与手机脚麻。在电话,它只是下载巨大的(20 MB)的数据,但没有显示实际地图。

Please tell me what is going wrong with the phone. In Phone it just download the huge(20 mb) data but not show the actual map.

logcat的即时得到 -

Logcat im getting -

   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 FILE

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

code

Code

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->的命令提示符

I just crated one api key as follow goto->cmd prompt

更改目录到密钥工具文件夹

change the directory to the keytool folder

现在运行命令的keytool -list -alias androiddebugkey -keystoreC:\ Users \用户pc.android \ debug.keystore-storepass安卓-keypass机器人

now run the command keytool -list -alias androiddebugkey -keystore "C:\Users\pc.android\debug.keystore" -storepass android -keypass android

看到的图像

see the image

现在我转到注册页面,我只是把MD5中的EditText和接受检查,并点击生成键,然后下面的页面出现该显示键 -

Now i goto signup page i simply put the MD5 in EditText and checked accept and clicked generate key then following page comes up which show the key--

现在我把这个钥匙在我的图形页面的Xml文件。

Now i put this key in my MapView Xml file..

正如你所看到的应用程序运行良好,在模拟器但不是在真正的手机。

as you can see app running fine in emulator but not in real phone.

我要去哪里错了,我怎么产生第二API密钥为一个真正的手机?

Where am I going wrong, and how do I generate a second API key for a real phone?

推荐答案

有关实际硬件测试,你需要使用一个密钥不同,调试的关键。随着你的帖子,你使用的是调试密钥库中。

For testing on real hardware you need to use a key different from the debug key. Following your post you are using a debug keystore.

http://$c$c.google.com/intl/it-IT/android/add-ons/google-apis/mapkey.html#getfingerprint

阅读谷歌的那一款。

重要的是,应用程序导出为一个签名的应用程序使用谷歌的API(不是调试键)相同的密钥。

Is important that the application is exported as a signed application with the same key used for the google api (and NOT the debug key).

有关创建有效的阅读段落:

For create a valid read that paragraph:

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

然后再使用相同的密钥来获得谷歌地图API密钥。

and then use the same key to obtain the google maps api key.

一旦你有钥匙您的应用程序,你可以通过点击鼠标在该项目的右键选择Android的工具,然后导出为签名的应用程序包导出一个签名的应用程序,然后按照向导(也许你可以创建一个新的关键的使用向导)。

Once you have the key for your application you can export a signed application by clicking with right button of your mouse on the project select Android Tools and then Export as a signed application package and follow the wizard (probably you can create a new key using that wizard).

希望帮助。

这篇关于Android的图形页面在手机和模拟器不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆